/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Track file upload progress using a handler

Copy link

If needed, you can track the progress of file upload using uploadFile(). The result would give the URL of the uploaded image that could be set as fileUrl in FileMessageCreateParams to send a file message.

const {
    requestId,
    url,
} = await channel.uploadFile({
    file,
    uploadStartedHandler: (requestId: string) => {
        // upload got started
    },
    progressHandler: (requestId: string, progress: number, total: number) => {
        // progress in percentage = progress / total
    },
});
channel.sendFileMessage({
    fileUrl: url,
    ...
})
...
.onSucceeded((message: FileMessage) => {
    // message is sent successfully
    ...
})