# customerServiceMessage.getTempMedia
Call this API at the server side. For more information, see Server API.
This API supports Cloud Calls. The WeChat DevTools version must be
1.02.1904090
or later (download the latest stable version here), and thewx-server-sdk
version must be0.4.0
or later.
Obtains temporary media from a customer service message. In other words, download temporary multimedia files. Only image files can be downloaded from Mini Programs.
Calling methods:
# HTTPS Call
# Request Address
GET https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
access_token | string | Yes | Credentials to call API | |
media_id | string | Yes | The ID of the media file |
# Return Value
# Buffer
An image buffer is returned.
# Exception Response
# Object
JSON
Property | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | Error message |
Valid values of errcode
Value | Description | Minimum Version |
---|---|---|
40007 | Invalid media file ID |
# Return Values
If the call is successful, binary content of the image is directly returned; if the call failed, data in the JSON format is returned.
# Calling Example
Execute CURL to upload a multimedia file via FORM.
curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"
# Cloud Call
Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via
wx-server-sdk
in the cloud function.
# API Calling Method
openapi.customerServiceMessage.getTempMedia
You need to configure the permissions for the
customerServiceMessage.getTempMedia
API viaconfig.json
. Details
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
mediaId | string | Yes | The ID of the media file |
# Return Value
# Object
Returns an object containing binary data and its data type.
Property | Type | Description |
---|---|---|
contentType | String | Data type (MIME Type) |
buffer | Buffer | Data buffer |
# Exceptions
# Object
JSON
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | Error message |
Valid values of errCode
Value | Description | Minimum Version |
---|
# SDK Calling Example
// cloud = require('wx-server-sdk')
// ...
// The method returns Promise
cloud.openapi.customerServiceMessage.getTempMedia({
mediaId: 'MEDIA_ID'
})
# SDK Calling Response Example
{
"errCode": 0,
"errMsg": "openapi.customerServiceMessage.getTempMedia:ok",
"contentType": "image/jpeg",
"buffer": Buffer
}
# Request Example
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.customerServiceMessage.getTempMedia({
mediaId: ''
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}