getFileDownloadURL method

dynamic getFileDownloadURL(
  1. List<String> fileIdList
)

获取文件下载链接

Implementation

getFileDownloadURL(List<String> fileIdList) async {
  if (fileIdList.isEmpty) {
    throw new CloudBaseException(
        code: CloudBaseExceptionCode.INVALID_PARAM,
        message: "fileIdList must not be empty");
  }

  List<Map<String, dynamic>> files = [];

  fileIdList.forEach((fileId) {
    files.add({'fileid': fileId, 'max_age': 1800});
  });

  Map<String, dynamic> data = {"file_list": files};

  CloudBaseResponse res =
      await _request.post("storage.batchGetDownloadUrl", data);

  // 存在 code,说明返回值存在异常
  if (res.code != null) {
    throw new CloudBaseException(code: res.code, message: res.message);
  }

  List<dynamic> dataList = res.data['download_list'];
  List<DownloadMetadata> list = [];
  dataList.forEach((item) {
    DownloadMetadata metadata = DownloadMetadata.fromMap(item);
    list.add(metadata);
  });

  CloudBaseStorageRes<List<DownloadMetadata>> getUrlRes =
      CloudBaseStorageRes(requestId: res.requestId!, data: list);
  return getUrlRes;
}