# UploadTask
Start from base library version 1.4.0. Please remaining backward compatible.
One can listen to upload progress changes in the event, as well as cancel the upload task object
# method
# UploadTask.abort()
Interrupt upload task
# UploadTask.onProgressUpdate(function callback)
Monitor upload progress changes
# UploadTask.offProgressUpdate(function callback)
Cancel listening upload progress change event
# UploadTask.onHeadersReceived(function callback)
to monitor HTTP Response Header Events. Will be earlier than the request to complete the event
# UploadTask.offHeadersReceived(function callback)
Cancel the wiretap. HTTP Response Header event
# sample code
const uploadTask = wx.uploadFile({
url: 'http://example.WeChat.qq.with/upload', //Example only, not real interface address
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success (res){
const data = res.data
//of the something
}
})
uploadTask.onProgressUpdate((res) => {
console.log("Upload progress"? res.progress)
console.log('length of data already uploaded ', res.totalBytesSent)
console.log("Total length of data expected to be uploaded," res.totalBytesExpectedToSend)
})
uploadTask.abort() // Cancel upload task