WeChat Mini Program Network API Upload and Download Detailed Instructions

高洛峰
Release: 2017-03-15 16:32:10
Original
1813 people have browsed it

This article mainly introduces the WeChat mini program networkAPI Upload, download detailed instructions related information, friends in need can refer to the following

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 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:

namekeyheaderformDatasuccessCallback function for successful interface callfailcompleteSample code:
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 corresponding 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
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"
  }
 })
 }
})
Copy after login

##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:



##Parameter TypeurlStringStringObjectFunctionFunctionFunctionSample code:
RequiredRequired
Yes URL for downloading resourcestype
NoThe type of downloading resources, used for Client identification processing, valid values: image/audio/videoheader
NoHTTP request Headersuccess
NoAfter the download is successful, it will be passed to the page in the form of tempFilePath, res={tempFilePath:"File Temporary path"}fail
NoCallback function that fails to call the interface complete
NoThe callback function at the end of the interface call (will be executed if the call is successful or failed)

wx.downloadFile({
 url: 'http://example.com/audio/123',
 type: 'audio',
 success:function(res){
 wx.playVoice({
  filePath: res.tempFilePath
 })
 }
})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template