cancelAttachmentUpload method

void cancelAttachmentUpload(
  1. String attachmentId, {
  2. String? reason,
})

Cancels attachmentId upload request. Throws exception if the request hasn't even started yet, Already completed or Already cancelled.

Optionally, provide a reason for the cancellation.

Implementation

void cancelAttachmentUpload(
  String attachmentId, {
  String? reason,
}) {
  final cancelToken = _cancelableAttachmentUploadRequest[attachmentId];
  if (cancelToken == null) {
    throw const StreamChatError(
      "Upload request for this Attachment hasn't started yet or maybe "
      'Already completed',
    );
  }
  if (cancelToken.isCancelled) {
    throw const StreamChatError('Upload request already cancelled');
  }
  cancelToken.cancel(reason);
}