SuperAPI AI Directory

feishu-upload-image

Design & creation

View repository

Updated 10-16 09:29

About this skill

Feishu Upload Image

Upload images to Feishu/Lark and get the image_key for use in messages.

Usage

Upload from Local File

python3 ./scripts/upload_image.py /path/to/image.jpg

Upload via HTTP

python3 ./scripts/upload_image.py --type message --image-type message https://example.com/image.jpg

Upload from Base64

python3 ./scripts/upload_image.py --base64 "iVBORw0KGgoAAAANS..."

Options

Option Description Default
`--type message avatar` Image usage type
`--image-type message avatar` Same as --type

Limits

  • Max file size: 10MB
  • Supported formats: JPEG, PNG, WEBP, GIF, TIFF, BMP, ICO
  • GIF resolution ≤ 2000×2000
  • Other formats ≤ 12000×12000

Response

Returns image_key which can be used in Feishu messages:

{
  "code": 0,
  "data": {
    "image_key": "img_v2_xxx"
  }
}

Guide to Sending Image Messages

Obtain the Necessary Information

  1. Feishu Access Token (tenant_access_token or app_access_token)
  2. Recipient ID (open_id, user_id, chat_id, or email)

Send Image Message API

Method 1: Send an Image Message Directly

curl -X POST https://open.feishu.cn/open-apis/im/v1/messages \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "receive_id": "{chat_id}",
    "msg_type": "image",
    "content": "{\"image_key\":\"{image_key}\"}"
  }'

Method 2: Embed an Image in Rich Text

curl -X POST https://open.feishu.cn/open-apis/im/v1/messages \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "receive_id": "{chat_id}",
    "msg_type": "post",
    "content": "{\"post\":{\"zh_cn\":{\"title\":\"图片消息\",\"content\":[[{\"tag\":\"img\",\"image_key\":\"{image_key}\"}]]}}}"
  }'

Get the Group Chat chat_id

  1. Open the group chat in Feishu and check the chat_id in the URL
  2. Or query the group chat list via the API:
curl -X GET https://open.feishu.cn/open-apis/im/v1/chats \
  -H "Authorization: Bearer {access_token}"

Practical Experience

  • After uploading an image, you get image_key, which is usually valid for 7 days
  • Before use, make sure you have the correct access token permissions
  • Sending a message requires the im:message:send_as_bot permission
  • It is recommended to upload the image first, then send the message, separating the two steps