# UploadTask wx.uploadFile(Object object)

Uploads local resources to the server. The client initiates an HTTPS POST request with content-type being multipart/form-data. Read related instructions before use.

# Parameters

# Object object

Attribute Type Default Required Description
url string Yes Developer server URL
filePath string Yes Path to upload a file
name string Yes Key of the file. The developer can get the binary content of the file on the server via this key.
header Object No HTTP request Header. Referer is not available in Header.
formData Object No Additional form data in the HTTP request
success function No The callback function for a successful API call
fail function No The callback function for a failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

# object.success callback function

# Parameters
# Object res
Property Type Description
data string Data returned by the developer server
statusCode number HTTP status code returned by the developer server

# Return Values

# UploadTask

Start from base library version 1.4.0. Please remaining backward compatible.

An object that can be used to listen on the upload progress event and cancel upload tasks.

# Sample Code

wx.chooseImage({
  success (res) {
    const tempFilePaths = res.tempFilePaths
    wx.uploadFile({
      url: 'https://example.weixin.qq.com/upload', //This value for demonstration purposes only is not a real API URL.
      filePath: tempFilePaths[0],
      name: 'file',
      formData: {
        'user': 'test'
      },
      success (res){
        const data = res.data
        //do something
      }
    })
  }
})