# customerServiceMessage.uploadTempMedia
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.1904090or later (download the latest stable version here), and thewx-server-sdkversion must be0.4.0or later.
Uploads a media file to the WeChat server.Only images are supported. This API is used to send customer service messages or passively reply messages to users.
Calling methods:
# HTTPS Call
# Request Address
POST https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| access_token | string | Yes | Credentials to call API | |
| type | string | Yes | The type of the file. | |
| media | FormData | Yes | The identifier of the media file in form-data, including information such as filename, filelength, and content-type. |
Valid values of type
| Value | Description | Minimum Version |
|---|---|---|
| image | Image |
# Return Value
# Object
JSON data package that is returned
| Property | Type | Description |
|---|---|---|
| errcode | number | Error code |
| errmsg | string | Error message |
| type | string | The type of the file. |
| media_id | string | The ID obtained after the media file is uploaded. It is valid within three days. |
| created_at | number | Upload timestamp of the media file. |
Valid values of errcode
| Value | Description | Minimum Version |
|---|---|---|
| 40004 | Invalid media file type |
Valid values of type
| Value | Description | Minimum Version |
|---|---|---|
| image | Image |
# Calling Example
Execute CURL to upload a multimedia file via FORM.
curl -F media=@test.jpg "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"
# Response Example
{
"errcode": 0,
"errmsg": "ok",
"type": "image",
"media_id": "MEDIA_ID",
"created_at": "xxx"
}
# 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-sdkin the cloud function.
# API Calling Method
openapi.customerServiceMessage.uploadTempMedia
You need to configure the permissions for the
customerServiceMessage.uploadTempMediaAPI viaconfig.json. Details
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| type | string | Yes | The type of the file. | |
| media | FormData | Yes | The data of the media file |
Valid values of type
| Value | Description | Minimum Version |
|---|---|---|
| image | Image |
media is composed as follows
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| contentType | string | Yes | The data type. It is MIME type. | |
| value | Buffer | Yes | The file buffer |
# Return Value
# Object
JSON data package that is returned
| Attribute | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
| type | string | The type of the file. |
| mediaId | string | The ID obtained after the media file is uploaded. It is valid within three days. |
| createdAt | number | Upload timestamp of the media file. |
Valid values of errCode
| Value | Description | Minimum Version |
|---|---|---|
| 0 | Succeeded |
Valid values of type
| Value | Description | Minimum Version |
|---|---|---|
| image | Image |
# Exceptions
# Object
Thrown Exceptions
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
Valid values of errCode
| Value | Description | Minimum Version |
|---|---|---|
| 40004 | Invalid media file type |
# SDK Calling Example
// cloud = require('wx-server-sdk')
// ...
// The method returns Promise
cloud.openapi.customerServiceMessage.uploadTempMedia({
type: 'image',
media: {
contentType: 'image/png',
value: Buffer
}
})
# Response Example
{
"errCode": 0,
"errMsg": "openapi.customerServiceMessage.uploadTempMedia:ok",
"type": "image",
"mediaId": "MEDIA_ID",
"createdAt": "xxx"
}