search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Network API Upload and Download Detailed Instructions

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"
  }
 })
 }
})

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

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools