fileUpload method

Future<HttpData> fileUpload({
  1. MultipartFile? multipartFile,
  2. String? url,
  3. String filePath = "",
  4. String key = 'file',
  5. String? fileName,
  6. String? method,
  7. FormData? formData,
  8. ProgressCallback? onSendProgress,
  9. ProgressCallback? onReceiveProgress,
  10. Function? onStart,
  11. Function? onError,
  12. Function? onFinish,
  13. dynamic handleRes(
    1. dynamic map
    )?,
  14. bool publicMethod = false,
})

-----------------------------------------上传文件方法封装-------------------------------------------------------------

Implementation

Future<HttpData> fileUpload({
  MultipartFile? multipartFile,
  String? url,
  String filePath = "",
  String key = 'file',
  String? fileName,
  String? method,
  FormData? formData,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
  Function? onStart,
  Function? onError,
  Function? onFinish,
  dynamic Function(dynamic map)? handleRes,
  bool publicMethod = false
}) async{

  MultipartFile file = multipartFile??await MultipartFile.fromFile(filePath, filename: fileName);

  return await request(
      url: url,
      method: method ?? Method.post,
      publicMethod: publicMethod,
      data: formData ?? FormData.fromMap({
        key: file
      }),
      onSendProgress: (int sent, int total){
        onSendProgress?.call(sent, total);
      },
      onReceiveProgress: (int sent, int total){
        onReceiveProgress?.call(sent, total);
      },
      handleRes: handleRes
  );

}