First, the new temporary material
No public often need to use some temporary scenes multimedia material, for example in the use of the interface in particular, to send a message, the operation of multimedia files, access and call multimedia messages, etc., are carried out by the media_id. Material management interface is open to all certified subscription number and service number. Through this interface, a number of the public can add temporary material (ie temporary upload multimedia files).
important point:
1, media_id temporary material is reusable.
2, the media file is saved in the micro-channel background time of 3 days, 3 days, i.e. media_id failure.
3, upload temporary clip format, the size limit is consistent with the public platform's official website.
Pictures (image): 2M, support the PNG \ JPEG \ JPG \ GIF format
Voice (voice): 2M, players no longer than 60s, supports AMR \ MP3 format
Video (video): 10MB, support MP4 format
Thumbnail (thumb): 64KB, JPG format support
4, use https call this interface.
Interface call requesting explanation
http request method: POST / FORM, use https https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE call sample (using curl command, a multimedia file upload form FORM way ): curl -F [email protected] "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"
Parameter Description
parameter | Do you have to | Explanation |
---|---|---|
access_token | Yes | Call Interface credentials |
type | Yes | Media file types, respectively picture (image), voice (voice), video (video) and thumbnail (thumb) |
media | Yes | form-data in the media file identification, there filename, filelength, content-type information |
Returning to the description
Where the correct return JSON packet under the following results:
parameter | description |
---|---|
type | Media file types, respectively picture (image), voice (voice), video (video) and thumbnail (thumb, mainly for the thumbnail video and music formats) |
media_id | After uploading your media files, obtain identification |
created_at | Media file upload timestamp |
Return packet error conditions the following example JSON (Example invalid media type error) at:
According to the above interface, we define a method to upload a temporary material, including the file directory and file type of these two parameters, we here still using RestTemplate tools for file upload
We create a new Controller to submit our upload request swagger in and test our code is correct
Our project started, enter a valid file path (if here is the picture type) in the swagger in, type set image
You can see, we have successfully uploaded the temporary files, and get to the media_id the file (this follow-up is very important !!!)
Second, obtain a temporary material
Temporary material is mainly divided into three categories (picture, audio, video), pictures and audio files downloaded to the local support, support for video file to obtain the URL of the video
(1) obtain a temporary Pictures
(2) obtain a temporary audio
(3) to obtain video footage address
Third, the test
Here we only temporary upload and download picture material temporary picture material, for example, we get a new type of material according to media_id temporary picture in our Controller Methods
We have just uploaded our successful return of temporary material media_id passed our approach
We can see our swagger returned with Download file hyperlinks, click here to download our pictures, of course, we can enter directly in the browser directly address our full request
Click the Download File, we have successfully downloaded to the temporary upload pictures
Here posted the complete code, self-modified to obtain other types of temporary files, not repeat them
Thank you, next time we continue to say!