This article describes how to upload and download detailed information about mini-program network APIs, for more information about uploading and downloading small program network APIs, see this article.
Wx. uploadFile (OBJECT)
Upload local resources to the developer server. For example, after obtaining a temporary file path for a local resource through the wx. chooseImage interface, you can use this interface to upload the local resource to the specified server. The client initiates an https post request, where Content-Type is multipart/form-data.
OBJECT parameter description:
Parameters |
Type |
Required |
Description |
Url |
String |
Yes |
Developer server url |
FilePath |
String |
Yes |
Path of the file resource to be uploaded |
Name |
String |
Yes |
The key corresponding to the file. the developer can use this key on the server to obtain the binary content of the file. |
Header |
Object |
No |
HTTP request Header |
FormData |
Object |
No |
Additional form data in the HTTP request |
Success |
Function |
No |
Callback function for successful API call |
Fail |
Function |
No |
Callback function for interface call failure |
Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
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 your local device. The client directly initiates an http get request to process the downloaded resource according to the type and return the local temporary path of the file.
OBJECT parameter description:
Parameters |
Type |
Required |
Required |
Url |
String |
Yes |
Download resource url |
Type |
String |
No |
Download resource type, used for client identification and processing. valid value: image/audio/video |
Header |
Object |
No |
HTTP request Header |
Success |
Function |
No |
After the download is successful, it is sent to the page in the form of tempFilePath, res = {tempFilePath: "Temporary file path "} |
Fail |
Function |
No |
Callback function for interface call failure |
Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', success:function(res){ wx.playVoice({ filePath: res.tempFilePath }) }})
Thank you for reading this article. I hope it will help you. thank you for your support for this site!
The above is the detailed description for uploading and downloading mini-program network APIs. For more information, see other related articles in the first PHP community!