WeChat mini program API upload and download
wx.uploadFile(OBJECT)
Upload local resources to the developer server. For example, after the page obtains the temporary file path of a local resource through an interface such as wx.chooseImage, it can upload the local resource to the designated server through this interface. The client initiates an HTTPS POST request where Content-Type
is multipart/form-data
.
OBJECT parameter description:
##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 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:
##Sample code:
wx.downloadFile({
url: 'http://example.com/audio/123',
type: 'audio',
success:function(res){
wx.playVoice({
filePath: res.tempFilePath
})
}
})