Official Accounts can use this API to get temporary assets (that is, to download temporary multimedia files). Note: Video files cannot be downloaded via HTTPS. This API must be called using the HTTP protocol.

This API was originally the "Download Multimedia Files" API.

API Request Format

HTTP request method: GET. HTTPS protocol is used.
https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
Request example (using the curl command to get multimedia files)
curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

Parameters

Parameter Required Description
access_token Yes The credential for API call
media_id Yes The ID of the media file

Response Description

The returned HTTP header for a successful request:

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 messages are returned, the content is as follows:

{
 "video_url":DOWN_URL
}

The returned JSON packet for a failed request (this is an example of invalid media file ID):

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

Debug this API using webpage debugging tool

Appendix: API for Getting HD Voices

Official Accounts can use this API to get a temporary voice uploaded using the uploadVoice API in the JS-SDK, which is in the speex format and at a sampling rate of 16 kHz. The audio file has a higher definition than the one (in the amr format and at a sampling rate of 8 kHz) obtained via the "Get Temporary Asset" API as mentioned above, suitable for use in speech recognition and other services that have higher audio quality requirements.

API Request Format

HTTP request method: GET. HTTPS protocol is used.
https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
Request example (using the curl command to get multimedia files)
curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

Parameters

Parameter Required Description
access_token Yes The credential for API call
media_id Yes Media file ID. It is the Server ID returned by the uploadVoice API

Response Description

The returned HTTP header for a successful request:

HTTP/1.1 200 OK
Connection: close
Content-Type: voice/speex
Content-disposition: attachment; filename="MEDIA_ID.speex"
Date: Sun, 06 Jan 2016 10:20:18 GMT
Cache-Control: no-cache, must-revalidate
Content-Length: 339721
curl -G "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

The returned JSON packet for a failed request (this is an example of invalid media file ID):

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

If the speex audio format does not meet your business requirements, you can transcode the obtained voice files locally.

Use Speex's official codec library (<a href="http://speex.org/downloads/ "http://speex.org/downloads/"" target="_blank">http://speex.org/downloads/) to transcode and combine with the Weixin codec library (including sample code: <a href="http://wximg.gtimg.com/shake_tv/mpwiki/declib.zip "Speex codec library"" target="_blank">Download URL).