ChannelFileUploadRequest constructor Null safety

ChannelFileUploadRequest(
  1. {required String channelUrl,
  2. required String requestId,
  3. required FileMessageParams params,
  4. OnUploadProgressCallback? onProgress}
)

Implementation

ChannelFileUploadRequest({
  required String channelUrl,
  required String requestId,
  required FileMessageParams params,
  OnUploadProgressCallback? onProgress,
}) : super() {
  url = 'storage/file';
  final fileSize = params.uploadFile.file?.lengthSync() ??
      params.uploadFile.fileBytes?.lengthInBytes ??
      0;
  if (fileSize == 0) {
    throw InvalidParameterError();
  }

  //upload size limit
  if (state.uploadSizeLimit < fileSize) {
    throw FileSizeLimitExceededError();
  }

  body = {
    'channel_url': channelUrl,
    'request_id': requestId,
    'file': params.uploadFile,
  };

  params.thumbnailSizes?.asMap().forEach((index, value) =>
      body['thumbnail${index + 1}'] =
          '${value.width.round()},${value.height.round()}');

  isMultipart = true;

  progress = onProgress;
}