You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Aspose.Cloud下载文件至本地?StorageApi所属库疑问

解决Aspose.Words-Cloud转换后云端文件下载问题

核心说明

StorageApi和GetDownloadRequest属于Aspose.Storage.Cloud .NET库,它是Aspose.Cloud生态中负责云端存储操作的核心组件,通常Aspose.Words.Cloud的SDK会自动依赖这个库,也可以单独通过NuGet安装:

Install-Package Aspose.Storage.Cloud

完善后的下载代码

原代码仅发起了下载请求,缺少将响应流保存到本地文件的逻辑,完整可运行的代码如下:

private static void downloadToLocal(Configuration config, string cloudFilePath, string localSavePath) 
{ 
    StorageApi storageApi = new StorageApi(config);
    GetDownloadRequest request = new GetDownloadRequest(); 
    request.Path = cloudFilePath; // 云端文件的完整路径,比如"converted-files/result.pdf"
    request.Storage = null; // 使用默认存储,若配置了自定义存储则填写名称
    request.VersionId = null; // 不需要版本控制时留空

    var response = storageApi.GetDownload(request);
    
    // 将响应流写入本地文件
    using (var fileStream = new FileStream(localSavePath, FileMode.Create))
    {
        response.CopyTo(fileStream);
    }
}

关键注意点

  • cloudFilePath需要和你调用Words转换API时指定的输出路径一致,比如调用ConvertDocument接口时设置的OutPath参数值。
  • 确保你的Configuration对象已经正确配置了AppKey、AppSID等身份验证信息,否则会返回权限错误。

内容的提问来源于stack exchange,提问作者Tushar Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 06:45:29