POST /open-apis/im/v1/images HTTP/1.1
Host: open.feishu.cn
Authorization: Bearer t-ddf4732fda4aa8a8b1639ee42e8477001d8d5f7c
Content-Length: 285
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image_type"
message
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="image.jpg"
Content-Type: image/jpeg
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gWimport requests
from requests_toolbelt import MultipartEncoder
# 输入pip install requests_toolbelt 安装依赖库
def uploadImage():
    url = "https://open.feishu.cn/open-apis/im/v1/images"
    form = {'image_type': 'message',
            'image': (open('path/testimage.png', 'rb'))}  # 需要替换具体的path 
    multi_form = MultipartEncoder(form)
    headers = {
        'Authorization': 'Bearer t-xxx',  ## 获取tenant_access_token, 需要替换为实际的token
    }
    headers['Content-Type'] = multi_form.content_type
    response = requests.request("POST", url, headers=headers, data=multi_form)
    print(response.headers['X-Tt-Logid'])  # for debug or oncall
    print(response.content)  # Print Response
if __name__ == '__main__':
    uploadImage()---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image_type";
message
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image";
Content-Type: application/octet-stream
二进制文件
---7MA4YWxkTrZu0gW| HTTP状态码 | 错误码 | 描述 | 排查建议 | 
|---|---|---|---|
| 400 | 234001 | Invalid request param. | 检查请求参数是否正确。 | 
| 401 | 234002 | Unauthorized. | 鉴权失败,联系Oncall解决。 | 
| 400 | 234006 | The file size exceed the max value. | 文件大小超出限制(文件:30M; 图片: 10M)。 | 
| 400 | 234007 | App does not enable bot feature. | 应用未启用机器人能力。 | 
| 400 | 234010 | File's size can't be 0. | 请勿上传大小为0的文件。 | 
| 400 | 234011 | can't_regonnize_image_format. | 不支 持的图片格式,目前仅支持上传 JPEG、PNG、WEBP、GIF、TIFF、BMP、ICO格式的图片。 | 
| 400 | 234039 | Image resolution exceeds limit. | GIF图片分辨率需要不大于2000x2000,其他图片分辨率需要不大于12000x12000。请使用上传文件接口以文件形式上传高分辨率图片。 | 
curl --location --request POST '/im/v1/images' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data; boundary=---7MA4YWxkTrZu0gW' \
--form 'image=@""' \
--form 'image_type="message"'{
    "code": 0,
    "data": {
        "image_key": "img_v2_xxx"
    },
    "msg": "ok"
}