Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
Message

Cancel an in-progress file upload

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);