WeChat Open Platform

Mini Programs Documentation

Temporary material interface

Get temporary materials

Mini Programs can use this interface to get temporary materials in Service Center messages (that is, download temporary multimedia files). Mini Programs currently only support downloading image files.

Interface call request descriptions

HTTP request methods: GET, HTTPS calls

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

Example request (example is a multimedia file obtained using curl command)

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

Parameter descriptions

Parameter Required Description
access_token Yes Calls interface credential
media_id Yes Media file ID

Return descriptions

The HTTP headers returned in a correct situation are 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 GMT
Cache-Control: no-cache, must-revalidate
Content-Length: 339721
curl -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

If video message materials are returned, the content is as follows:

{
 "video_url":DOWN_URL
}

An example JSON packet returned in an error situation is shown below (the example is an invalid media ID error):

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

New temporary materials

Mini Programs can use this interface to upload media files (currently only images are supported) to the WeChat server, send users Service Center messages, or reply passively to user messages.

Interface call request descriptions

HTTP request methods: POST/FORM, HTTPS call

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

Example call (using curl command and FORM method to upload a multimedia file):

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

Parameter descriptions

Parameter Required Description
access_token Yes Calls interface credential
type Yes image
media Yes Media file IDs in form-data, there is information including filename, filelength and content-type

Return descriptions

The JSON packet results returned in a correct situation are as follows:

{
  "type":"TYPE",
  "media_id":"MEDIA_ID",
  "created_at":123456789
}
Parameter Description
type image
media_id ID obtained after media file is uploaded
created_at Media file upload timestamp

An example JSON packet returned in an error situation is shown below (the example is an invalid media type error):

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