Browse SDKs · Flutter
Platform
SDKsFlutter

Listen for file upload progress

Configure the standalone file upload listener in the OpenIM Flutter SDK.

Copy

Configure a standalone file upload listener centrally within your application upload management service:

Parameters

ParameterTypeRequiredDescription
listenerOnUploadFileListenerYesUpload listener instance providing file upload progress and completion callbacks.

OnUploadFileListener callback methods provide the following arguments:

  • onUploadProgress(id, fileSize, streamSize, storageSize): Task ID, total file size in bytes, stream bytes read, and bytes written to storage.
  • onComplete(id, size, url, type): Task ID, final file size in bytes, remote accessible URL, and storage type.

Code example

OpenIM.iMManager.setUploadFileListener(
  OnUploadFileListener(
    onUploadProgress: (id, fileSize, streamSize, storageSize) {
      updateFileProgress(id, streamSize, fileSize);
    },
    onComplete: (id, size, url, type) {
      completeFileUpload(id, size, url, type);
    },
  ),
);

State changes after the call

The Flutter SDK maintains only a single OnUploadFileListener instance; setting a new listener replaces the previous one. Register this listener once in your application state layer, rather than inside individual UI widgets, to prevent callbacks from being inadvertently overwritten.

Callbacks identify upload jobs by the task id. Do not rely on file names or array indexes to map upload progress to UI items. When switching accounts or destroying the upload manager, stop forwarding events to inactive views and clear the active task registry.

To initiate file uploads, refer to Upload a file.