uploadMediaFile method

Future<UploadMediaFileResult> uploadMediaFile({
  1. required Uint8List bytes,
  2. required String filename,
  3. int? width,
  4. int? height,
  5. CancelToken? cancelToken,
  6. void onSendProgress(
    1. int sent,
    2. int total
    )?,
})

上传媒体(头像裁剪、聊天图片/视频封面等)

POST /api/v1/upload/media-file,字段:file,可选 width / height。

Implementation

Future<UploadMediaFileResult> uploadMediaFile({
  required Uint8List bytes,
  required String filename,
  int? width,
  int? height,
  CancelToken? cancelToken,
  void Function(int sent, int total)? onSendProgress,
}) async {
  final form = FormData.fromMap({
    'file': MultipartFile.fromBytes(bytes, filename: filename),
    if (width != null && width > 0) 'width': '$width',
    if (height != null && height > 0) 'height': '$height',
  });
  final resp = await _net.http.postFormData(
    '/api/v1/upload/media-file',
    data: form,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
  );
  return UploadMediaFileResult.fromJson(resp);
}