content-type
is multipart/form-data
. Prior to usage, read relevant instructions.Attribute | Type | Default value | Required | Description |
url | string | - | Yes | Developer Server Address |
filePath | string | - | Yes | Path to the file resource to be uploaded (local path) |
name | string | - | Yes | The corresponding key for the file, through which developers can access the binary content of the file on the server side. |
header | object | - | No | HTTP request's Header; setting Referer within the Header is not allowed. |
formData | object | - | No | Additional form data in the HTTP request |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
data | string | Data returned from the developer's server. |
statusCode | number | HTTP status code returned from the developer's server. |
wx.chooseImage({success (res){const tempFilePaths = res.tempFilePathswx.uploadFile({url: 'https://example.weixin.qq.com/upload', // This is merely an example and not an actual interface address.filePath: tempFilePaths[0],name: 'file',formData:{'user': 'test'},success (res){const data = res.data//do something}})}})
This method is used via UploadTask.abort().
This method is used via UploadTask.onProgressUpdate(function listener).
Attribute | Type | Description |
progress | number | Download progress percentage |
totalBytesWritten | number | Length of the data already downloaded, measured in Bytes. |
totalBytesExpectedToWrite | number | Total length of the data expected to be downloaded, measured in bytes. |
This method is used via UploadTask.offProgressUpdate(function listener).
const listener = function (res) { console.log(res) }DownloadTask.onProgressUpdate(listener)DownloadTask.offProgressUpdate(listener) // The same function object as the listener must be passed in.
This method is used via UploadTask.onHeadersReceived(function listener).
Attribute | Type | Description |
header | Object | HTTP Response Header returned from the developer's server. |
This method is used via UploadTask.offHeadersReceived(function listener).
const listener = function (res) { console.log(res) }UploadTask.onHeadersReceived(listener)UploadTask.offHeadersReceived(listener) // The same function object as the listener must be passed in.
const uploadTask = wx.uploadFile({url: 'http://example.weixin.qq.com/upload', // This is merely an example and not an actual interface address.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('Length of already uploaded data', res.totalBytesSent)console.log('Total length of data expected to be uploaded', res.totalBytesExpectedToSend)})uploadTask.abort() // Aborts upload task
Was this page helpful?