Example #1
0
        // 下载文件
        async Task DownloadFileAsync(string cloudPath, string filePath)
        {
            if (string.IsNullOrEmpty(cloudPath))
            {
                throw new CloudBaseException(CloudBaseExceptionCode.EMPTY_PARAM, "下载的云端文件路径不能为空");
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new CloudBaseException(CloudBaseExceptionCode.EMPTY_PARAM, "下载的本地文件路径不能为空");
            }

            GetDownloadUrlResponse metadataRes = await this.GetFileDownloadUrlAsync(new List <string> {
                cloudPath
            });

            if (!string.IsNullOrEmpty(metadataRes.Code))
            {
                throw new CloudBaseException(metadataRes.Code, metadataRes.Message);
            }

            await this.core.Request.DownloadAsync(metadataRes.FileList[0].DownloadUrl, filePath);
        }
Example #2
0
        public async Task <GetDownloadUrlResponse> GetFileDownloadUrlAsync(List <string> fileIdList)
        {
            if (fileIdList == null || fileIdList.Count <= 0)
            {
                throw new CloudBaseException(CloudBaseExceptionCode.EMPTY_PARAM, "下载文件列表不能为空");
            }

            List <Dictionary <string, dynamic> > files = new List <Dictionary <string, dynamic> >();

            for (int i = 0; i < fileIdList.Count; i++)
            {
                Dictionary <string, dynamic> file = new Dictionary <string, dynamic>();
                file.Add("fileid", fileIdList[i]);
                file.Add("max_age", 1800);
                files.Add(file);
            }

            Dictionary <string, dynamic> param = new Dictionary <string, dynamic>();

            param.Add("file_list", files);
            GetDownloadUrlResponse res = await this.core.Request.PostAsync <GetDownloadUrlResponse>("storage.batchGetDownloadUrl", param);

            return(res);
        }