# 上传图片消息

# 接口说明

通过该接口,商家客服可以上传多媒体资源(如图片、视频、文件等)至微信服务器,以便在客服会话中使用。

# 注意事项

  • ​文件大小限制:
    • 图片:不超过30MB。
    • 有效期:上传的媒体文件在微信服务器上保存14天,过期后自动删除。

# 接口调用请求说明

  • ​使用场景:上传的多媒体资源可用于客服会话中的消息发送。

HTTP
POST https://api.weixin.qq.com/channels/ec/commkf/cosupload?access_token=ACCESS_TOKEN

# 请求参数示例(图片消息)

  • 使用 form-data 表单 格式 在请求的 Body 中选择 form-data,并添加以下字段:
参数 类型 是否必填 描述 字段示例
file File 需要上传的视频/图片/文件。 postman-cloud:///xxxx-xxxx-xxxx-xxx-xxxx
open_id Text 用户的 open_id,用于标识上传资源的用户。 o7eep4jVQelr2eyoDSmE1xxxxxx
msg_type Text 文件类型,目前支持的文件类型有(video/file/image) image
示例Curl

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"'

# 返回参数说明

参数 类型 描述
errcode number 错误码
errmsg string 错误信息
cos_url string 多媒体cos_url

# 返回参数示例

{
    "cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxxxxxxxxx&openid=o7eep4jVQelr2eyoDSmE1xxxxxx&msg_type=2",
    "errcode": 0,
    "errmsg": "ok"
}