/ SDKs / Flutter
SDKs
Chat SDKs Flutter v4
Chat SDKs Flutter
Chat SDKs
Flutter
Version 4

Cancel an in-progress file upload

Copy link

Using the cancelFileMessageUpload() method, you can cancel an in-progress file upload while it hasn't been completed yet. If the function operates successfully, the value of true is returned.

Note: If you attempt to cancel the upload after it has already been completed or canceled, or the attempt results in an error, the function returns the value of false.

try {
    final completer = Completer();
    final message = channel.sendFileMessage(
      FileMessageCreateParams.withFile(FILE),
      handler: (message, e) {
        expect(e, isNotNull);
        expect(e, isA<OperationCanceledException>());
        completer.complete();
      },
    );
    final result = channel.cancelFileMessageUpload(message.requestId!);
    await completer.future;
    expect(result, true);
} catch (e) {
  // Handle error.
}