deleteFiles method

dynamic deleteFiles(
  1. List<String> fileIdList
)

删除文件

Implementation

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

  fileIdList.forEach((fileId) {
    _checkParams(fileId, 'fileIdList must not have empty string');
  });

  Map<String, dynamic> data = {'fileid_list': fileIdList};
  CloudBaseResponse res =
      await _request.post('storage.batchDeleteFile', data);

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

  // 格式化处理返回数据
  List<dynamic> dataList = res.data['delete_list'];
  List<DeleteMetadata> list = [];
  dataList.forEach((item) {
    DeleteMetadata metadata = DeleteMetadata.fromMap(item);
    list.add(metadata);
  });

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