# wx.cloud.uploadFile

Uploads local resources to the cloud storage. If uploaded to the same path, it will be overwritten.

Request parameters

Field Description Data Type Default Required
cloudPath Cloud storage path. For naming rules, see File Naming Rules String - Y
filePath Path to upload a file String - Y
header HTTP request Header, Referer is not available in header Object - N
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
fileID File ID 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

Return value

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

# Use Case

Callback style

wx.cloud.uploadFile({
  cloudPath: 'example.png',
  filePath: '', // File path
  success: res => {
    // get resource ID
    console.log(res.fileID)
  },
  fail: err => {
    // handle error
  }
})

Promise style

wx.cloud.uploadFile({
  cloudPath: 'example.png',
  filePath: '', // File path
}).then(res => {
  // get resource ID
  console.log(res.fileID)
}).catch(error => {
  // handle error
})