uploadOSSFile function

Future<Result> uploadOSSFile({
  1. required String filepath,
  2. required String policy,
  3. required String accessKeyId,
  4. required String signature,
  5. required String key,
  6. required String host,
  7. String successActionStatus = "204",
  8. Duration connectTimeout = const Duration(seconds: 60),
  9. BaseCancelToken? cancelToken,
  10. ProgressCallback? onSendProgress,
})

上传文件

Implementation

Future<Result> uploadOSSFile({
  required String filepath,
  required String policy,
  required String accessKeyId,
  required String signature,
  required String key,
  required String host,
  String successActionStatus = "204",
  Duration connectTimeout = const Duration(seconds: 60),
  BaseCancelToken? cancelToken,
  ProgressCallback? onSendProgress,
}) async {
  final extensionName = getExtension(filepath);
  final fileName = '${timestampNow()}$extensionName';
  // https://help.aliyun.com/zh/oss/developer-reference/postobject?spm=a2c4g.11186623.0.0.65254563hDuDeM
  final multipartFile = await MultipartFile.fromFile(
    filepath,
    filename: fileName,
  );
  final data = FormData.fromMap({
    'file': multipartFile,
    'policy': policy,
    'OSSAccessKeyId': accessKeyId,
    'Signature': signature,
    'key': key,
    'success_action_status': successActionStatus,
  });
  final result = await post(
    baseUrl: host,
    connectTimeout: connectTimeout,
    cancelToken: cancelToken,
    data: data,
    onSendProgress: onSendProgress,
    validResult: false,
  );
  return result;
}