Transferring Multimedia Files
Back

From WeChat Official Account Admin Platform
Jump to: navigation, search

Official accounts obtain and call multimedia files and messages using a media id that enables multimedia files to be uploaded to and downloaded from official accounts. Note that multimedia files are removed from the WeChat server after three days to recycle space.

Uploading Multimedia Files

Official accounts can upload image, audio and video files to the WeChat server using this API. The system then returns a corresponding media ID that enables official accounts to obtain multimedia files. Note that the media id is reusable and that you need to use HTTP protocol to call this API.

Request Description

HTTP request mode: POST/FORM
http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
An example of uploading a multimedia file in FORM mode using the CURL command is as follows:
 curl -F media=@test.jpg "http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

Parameter Description

Parameter Required Description
access_token Yes The certificate for calling API
type Yes Media file type including image, voice, video and thumb.
media Yes Media file identity in form-data including filename, file length, and content type

Return Description

An example of a successful JSON response is as follows:

{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
Parameter Description
type Media file type including image, voice, video and thumb (used for video and music files)
media_id The unique ID obtained after uploading multimedia files
created_at Timestamp for uploading multimedia files

An example of an unsuccessful JSON response (caused by invalid media type) is as follows:

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

Follow the rules below when uploading multimedia files:

  • Image (image): 128K, supports for JPG
  • Audio (voice): 256K, no more than 60s play time, and supports for AMR
  • Video (video): 1MB, supports for MP4
  • Thumb (thumb): 64KB, supports for JPG

Multimedia files remain on the WeChat server for three days. The media id expires after three days.

Obtaining Multimedia Files

Official accounts call this API to obtain multimedia files. Use the HTTP protocol to call this API.

Request Description

HTTP request method: GET
http://file.api.wechat.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
An example of downloading a multimedia file using the CURL command is as follows:
curl -I -G "http://file.api.wechat.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

Parameter Description

Parameter Required Description
access_token Yes The certificate for calling API
media_id Yes Media file ID


Return Description An example of an HTTP head response 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 GMT
Cache-Control: no-cache, must-revalidate
Content-Length: 339721
curl -G "http://file.api.wechat.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

An example of an unsuccessful JSON response (caused by invalid media id) is as follows:

{"errcode":40007,"errmsg":"invalid media_id"}
Developer Guide
Custom-defined Menu
WeChat JS-SDK