This article mainly introduces the WeChat mini program networkAPI Upload, download detailed instructions related information, friends in need can refer to the following
Upload local resources to the developer server. For example, after the page obtains the temporary file path of a local resource through wx.chooseImage and other interfaces, it can upload the local resource to the designated server through this interface. The client initiates an HTTPS POST request, where the Content-Type is multipart/form-data .
OBJECT parameter description:
Parameter | Type | Required | Description |
---|---|---|---|
url | String | is the | developer server url |
filePath | String | is the path to the file resource to be uploaded | |
String | is the | keycorresponding to the | file. Developers can obtain the binary content of the file through this key on the server side |
Object | No | HTTP Request Header | |
Object | No | Other additional form data in the HTTP request | |
Function | No | Callback function for successful interface call | |
Function | No | Callback function for interface call failure | |
Function | No | Callback function for interface call completion (successful call , will be executed if it fails) |
wx.chooseImage({ success:function(res){ var tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: 'http://example.com/upload', filePath: tempFilePaths[0], name:"file", formData:{ "user":"test" } }) } })
##wx. downloadFile(OBJECT)
Download file resources to the local. The client directly initiates an HTTP GET request, processes the downloaded resource according to type, and returns the local temporary path of the file.
OBJECT parameter description:
Required | Required | ||
---|---|---|---|
Yes | URL for downloading resources | type | |
No | The type of downloading resources, used for Client identification processing, valid values: image/audio/video | header | |
No | HTTP request Header | success | |
No | After the download is successful, it will be passed to the page in the form of tempFilePath, res={tempFilePath:"File Temporary path"} | fail | |
No | Callback function that fails to call the interface | complete | |
No | The callback function at the end of the interface call (will be executed if the call is successful or failed) | Sample code: |
wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', success:function(res){ wx.playVoice({ filePath: res.tempFilePath }) } })
Thank you for reading, I hope it can help everyone, thank you for your support of this site!
The above is the detailed content of WeChat Mini Program Network API Upload and Download Detailed Instructions. For more information, please follow other related articles on the PHP Chinese website!