WeChat applet network API upload and download details

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.