# wx.cloud.downloadFile

Downloads files from cloud storage.

Request parameters

Field Description Data Type Default Required
fileID Cloud file ID String - Y
config Configuration Object - N
success Callback succeeds
fail Callback fails
complete Callback completes

config object definition

Field Description Data Type
env ID of the used environment. Ignore the environment specified by init if this parameter is specified. String

success return parameter

Field Description Data Type
tempFilePath Temporary file path String
statusCode HTTP status code returned by the server Number

fail return parameter

Field Description Data Type
errCode Error code Number
errMsg Error message, in the format of apiName:fail msg String

# Use Case

Callback style

wx.cloud.downloadFile({
  fileID: 'a7xzcb',
  success: res => {
    // get temp file path
    console.log(res.tempFilePath)
  },
  fail: err => {
    // handle error
  }
})

Promise style

wx.cloud.downloadFile({
  fileID: 'a7xzcb'
}).then(res => {
  // get temp file path
  console.log(res.tempFilePath)
}).catch(error => {
  // handle error
})

Return value If a callback of success/fail/complete is included in the request parameter, an downloadTask object is returned. Upload progress events can be monitored and upload tasks can be canceled via the downloadTask object.

点击咨询小助手