# cloud.downloadFile

从云存储空间下载文件

请求参数

字段 说明 数据类型 默认值 必填
fileID 云文件 ID String - Y
config 配置 Object - N
success 成功回调
fail 失败回调
complete 结束回调

config 对象定义

字段 说明 数据类型
env 使用的环境 ID,填写后忽略 init 指定的环境 String

success 返回参数

字段 说明 数据类型
data 文件内容 ArrayBuffer
statusCode 服务器返回的 HTTP 状态码 Number
errMsg 成功为 downloadFile:ok,失败为失败原因 String

fail 返回参数

字段 说明 数据类型
errCode 错误码 Number
errMsg 错误信息,格式 downloadFile:fail msg String

# 使用示例

Callback 风格

cloud.downloadFile({
  fileID: 'a7xzcb',
  success: res => {
    console.log(res.data)
  },
  fail: err => {
    // handle error
  }
})

Promise 风格

wx.cloud.downloadFile({
  fileID: 'a7xzcb'
}).then(res => {
  console.log(res.data)
}).catch(error => {
  // handle error
})

返回值 如果请求参数中带有 success/fail/complete 回调中的任一个,则会返回一个 downloadTask 对象,通过 downloadTask 对象可监听上传进度变化事件,以及取消上传任务。