# 上传多媒体资源
接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南
接口英文名:cosupload
通过该接口,商家客服可以上传多媒体资源(如图片、视频、文件等)至微信服务器,以便在客服会话中使用。
使用场景:上传的多媒体资源可用于客服会话中的消息发送。
相关事件通知:客服消息事件
# 1. 调用方式
# HTTPS 调用
POST https://api.weixin.qq.com/channels/ec/commkf/cosupload?access_token=ACCESS_TOKEN
# 云调用
- 本接口不支持云调用
# 第三方调用
- 本接口不支持第三方平台调用。
# 2. 请求参数
# 查询参数 Query String parameters
参数名 | 类型 | 必填 | 示例 | 说明 |
---|---|---|---|---|
access_token | string | 是 | ACCESS_TOKEN | 接口调用凭证,可使用 access_token |
# 请求体 Request Payload
参数名 | 类型 | 必填 | 示例 | 说明 |
---|---|---|---|---|
msg_type | string | 是 | file | 文件类型,目前支持的文件类型有(video/file/image) |
open_id | string | 是 | o7eep4jVQelr2eyoDSmE1xxxxxx | 用户的 open_id,用于标识上传资源的用户。 |
file | formdata | 是 | postman-cloud:///xxxx-xxxx-xxxx-xxx-xxxx | 需要上传的视频/图片/文件。 |
# 3. 返回参数
# 返回体 Response Payload
参数名 | 类型 | 示例 | 说明 |
---|---|---|---|
cos_url | string | https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxx&msg_type=xxx | 多媒体cos_url |
errmsg | string | ok | 错误信息 |
errcode | number | 0 | 错误码 |
# 4. 注意事项
文件类型:支持上传的媒体文件类型包括图片(image)、视频(video)、文件(file)等。
文件大小限制:
1、图片:不超过30MB;
2、视频:不超过30MB。
3、文件:不超过30MB。
4、有效期:上传的媒体文件在微信服务器上保存14天,过期后自动删除。
# 5. 代码示例
# 5.1 上传文件消息
请求示例
curl --location 'https://api.weixin.qq.com/channels/ec/commkf/cosupload?access_token=xxxxxxx' \
--form 'file=@"xxxxxxx"' \
--form 'open_id="xxxxxxxxx"' \
--form 'msg_type="file"'
返回示例
{
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxx&msg_type=xxx",
"errmsg": "ok",
"errcode": 0
}
# 5.2 上传图片消息
请求示例
curl --location 'https://api.weixin.qq.com/channels/ec/commkf/cosupload?access_token=xxxxxxx' \
--form 'file=@"xxxxxxx"' \
--form 'open_id="xxxxxxxxx"' \
--form 'msg_type="image"'
返回示例
{
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx×tamp=xxxxx&openid=xxxxxx&msg_type=xxx",
"errmsg": "ok",
"errcode": 0
}
# 5.3 上传视频消息
请求示例
curl --location 'https://api.weixin.qq.com/channels/ec/commkf/cosupload?access_token=xxxxxxx' \
--form 'file=@"xxxxxxx"' \
--form 'open_id="xxxxxxxxx"' \
--form 'msg_type="video"'
返回示例
{
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxxxxxxxxx&openid=o7eep4jVQelr2eyoDSmE1xxxxxx&msg_type=7",
"errcode": 0,
"errmsg": "ok"
}
# 6. 错误码
此接口没有特殊错误码,可参考 通用错误码
# 7. 适用范围
本接口支持「微信小店(需申请)」账号类型调用。其他账号类型如无特殊说明,均不可调用。