postFileByFormData method

dynamic postFileByFormData({
  1. required String url,
  2. required String? filePath,
  3. required Map<String, dynamic> metadata,
  4. void onProcess(
    1. int count,
    2. int total
    )?,
})

使用 form 表单传递文件

Implementation

postFileByFormData(
    {required String url,
    required String? filePath,
    required Map<String, dynamic> metadata,
    void onProcess(int count, int total)?}) async {
  if (filePath == null) {
    throw new CloudBaseException(
        code: CloudBaseExceptionCode.EMPTY_PARAM,
        message: 'filePath cloud not be empty');
  }

  print(filePath);

  Map<String, dynamic> data = {};
  data.addAll(metadata);
  data.addAll({"file": await MultipartFile.fromFile(filePath)});
  FormData formData = FormData.fromMap(data);
  await _dio.post(url, data: formData, onSendProgress: onProcess);
}