# UploadTask wx.uploadFile(Object object)
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6
Uploads local resources to the server. The client initiates a HTTPS POST Request, wherein content-type
for multipart/form-data
. Please read theRelated notes。
# parameter
# Object object
attribute | type | Default values | Required | Introductions | Minimum version |
---|---|---|---|---|---|
url | string | yes | Developer Server Address | ||
filePath | string | yes | Path to upload file resource (Local path) | ||
name | string | yes | File corresponding to Key, developers on the server side can use this key Get the binary content of the file | ||
header | Object | no | HTTP request Header,Header Can not be set Refer | ||
formData | Object | no | HTTP Additional requests form data | ||
timeout | number | no | Timeout in milliseconds | 2.10.0 | |
success | function | no | Interface calls the successful callback function | ||
fail | function | no | Interface calls failed callback functions | ||
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
data | string | Data returned by the developer server |
statusCode | number | Returned by the developer server HTTP Status code |
# Return value
# UploadTask
Start from base library version 1.4.0. Please remaining backward compatible.
An object that listens for changes in the upload progress and cancels uploads
# sample code
wx.chooseImage({
success (res) {
const tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'https://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
}
})
}
})
The translations are provided by WeChat Translation and are for reference only. In case of any inconsistency and discrepancy between the Chinese version and the English version, the Chinese version shall prevail.Incorrect translation. Tap to report.