# UploadTask

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

Listens on the upload progress change event and cancels upload tasks.

# Methods

# UploadTask.abort()

Aborts upload tasks.

# UploadTask.onProgressUpdate(function callback)

Listens on the upload progress change event.

# UploadTask.offProgressUpdate(function callback)

Un-listens on the upload progress change event.

# UploadTask.onHeadersReceived(function callback)

Listens on HTTP Response Header event, which will be earlier than the request completion event.

# UploadTask.offHeadersReceived(function callback)

Un-listens on the HTTP Response Header event.

# Sample Code

const uploadTask = wx.uploadFile({
  url: 'http://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
  }
})

uploadTask.onProgressUpdate((res) => {
  console.log('Upload progress', res.progress)
  console.log('The length of uploaded data', res.totalBytesSent)
  console.log('The length of data expected to be uploaded', res.totalBytesExpectedToSend)
})

uploadTask.abort() // Cancel upload tasks
点击咨询小助手