WeChat Mini Program API Temporary Material Interface


Temporary material interface


Get temporary material

The applet can use this interface to obtain the temporary material in the customer service message (that is, download the temporary multimedia file). Currently, the mini program only supports downloading image files.

Interface call request description

HTTP request method: GET, HTTPS call

https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID

Request example (the example is to obtain multimedia files through the curl command)

curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

Parameter description

ParameterIs it necessaryDescription
access_token is the calling interface credential
media_id is the media file ID

Return instructions

The return HTTP header under correct circumstances is as follows:

HTTP/1.1 200 OK
Connection: close
Content-Type: image/jpeg 
Content-disposition: attachment; filename="MEDIA_ID.jpg"
Date: Sun, 06 Jan 2013 10:20:18 GMTCache-Control: no-cache, must-revalidateContent-Length: 339721curl -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

If the video message material is returned, the content is as follows:

{
 "video_url":DOWN_URL
}

The example of the returned JSON data packet in the error situation is as follows (the example is invalid media ID error):

{ 
 "errcode":40007,  "errmsg":"invalid media_id"
 }

Add temporary material

The applet can use this interface to store media files (Currently only images are supported) Upload to the WeChat server, and the user sends customer service messages or passively replies to user messages.

Interface call request description

HTTP request method: POST/FORM, HTTPS call

https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE

Call example (use the curl command to upload a multimedia file using the FORM form):

curl -F media=@test.jpg "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

Parameter description

QQ截图20170208153019.png

Return description

The returned JSON data packet result under correct conditions is as follows:

{
  "type":"TYPE",
  "media_id":"MEDIA_ID",
  "created_at":123456789
}

QQ截图20170208153036.png

The example of the returned JSON data packet in the error case is as follows (the example is invalid media type error):

{
  "errcode":40004,
  "errmsg":"invalid media type"
}