uploadFile method

dynamic uploadFile({
  1. required String cloudPath,
  2. required String filePath,
  3. void onProcess(
    1. int count,
    2. int total
    )?,
})

上传文件

Implementation

uploadFile(
    {required String cloudPath,
    required String filePath,
    void onProcess(int count, int total)?}) async {
  _checkParams(cloudPath, 'cloudPath is required');
  _checkParams(filePath, 'filePath is required');

  CloudBaseStorageRes<UploadMetadata> metadataRes =
      await getUploadMetadata(cloudPath);
  UploadMetadata metadata = metadataRes.data;

  Map<String, String> data = {
    'key': cloudPath,
    'signature': metadata.authorization,
    'x-cos-meta-fileid': metadata.cosFileId,
    'x-cos-security-token': metadata.token
  };

  // 上传文件,正常的情况响应为空
  await _request.postFileByFormData(
      url: metadata.url,
      metadata: data,
      filePath: filePath,
      onProcess: onProcess);

  CloudBaseStorageRes<UploadRes> res = CloudBaseStorageRes(
      requestId: metadataRes.requestId,
      data: UploadRes.fromMap({'fileId': metadata.fileId}));
  return res;
}