/ SDKs / Flutter
SDKs
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Flutter
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

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.

    final file = await getAssetFrom('resources/video.mp4');
    final params = FileMessageParams.withFile(file);

    final completer = Completer();
    final pending = channel.sendFileMessage(
      params,
      onCompleted: (message, error) {
        expect(error, isNotNull);
        expect(error, isA<OperationCancelError>());
        completer.complete();
      },
    );
    final res = channel.cancelUploadingFileMessage(pending.requestId!);
    await completer.future;
    expect(res, isTrue);