wx.cloud.downloadFile
wx.cloud.downloadFile
从云存储空间下载文件
请求参数
字段 | 说明 | 数据类型 | 默认值 | 必填 |
---|---|---|---|---|
fileID | 云文件 ID | String | - | Y |
config | 配置 | Object | - | N |
success | 成功回调 | |||
fail | 失败回调 | |||
complete | 结束回调 |
config 对象定义
字段 | 说明 | 数据类型 |
---|---|---|
env | 使用的环境 ID,填写后忽略 init 指定的环境 | String |
success 返回参数
字段 | 说明 | 数据类型 |
---|---|---|
tempFilePath | 临时文件路径 | String |
statusCode | 服务器返回的 HTTP 状态码 | Number |
errMsg | 成功为 downloadFile:ok,失败为失败原因 | String |
fail 返回参数
字段 | 说明 | 数据类型 |
---|---|---|
errCode | 错误码 | Number |
errMsg | 错误信息,格式 downloadFile:fail msg | String |
使用示例
Callback 风格
wx.cloud.downloadFile({
fileID: 'a7xzcb',
success: res => {
// get temp file path
console.log(res.tempFilePath)
},
fail: err => {
// handle error
}
})
Promise 风格
wx.cloud.downloadFile({
fileID: 'a7xzcb'
}).then(res => {
// get temp file path
console.log(res.tempFilePath)
}).catch(error => {
// handle error
})
返回值 如果请求参数中带有 success/fail/complete 回调中的任一个,则会返回一个 downloadTask 对象,通过 downloadTask 对象可监听下载进度变化事件,以及取消下载任务。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 我与微信审核的“相爱相杀”看个人小程序副业