/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Track file upload progress using a handler

Copy link

If needed, you can track the progress of file upload by passing FileMessageWithProgressHandler as an argument to a parameter when calling the sendFileMessage() method.

val params = FileMessageCreateParams(FILE).apply {
    fileName = FILE_NAME
    data = DATA
    customType = CUSTOM_TYPE
}

val fileMessage = channel.sendFileMessage(
    params,
    object : FileMessageWithProgressHandler {
        override fun onProgress(bytesSent: Int, totalBytesSent: Int, totalBytesToSend: Int) {
            val percent = (totalBytesSent * 100) / totalBytesToSend
        }

        override fun onResult(message: FileMessage?, e: SendbirdException?) {
            if (e != null) {
                // Handle error.
            }

            // You can handle actions relevant to the sent file message.
            // ...
        }
    }
)