uploadOSSFile function
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,
上传文件
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;
}