Prerequisite: Read
../lark-shared/SKILL.mdfirst to understand authentication, global parameters, and safety rules.
Download image or file resources from a message. Supports automatic chunked download for large files using HTTP Range requests. Resources are identified by the combination of message_id + file_key, both of which come directly from message content returned by im +chat-messages-list.
Note: read-only message commands render resource keys in message content, but they do not download binaries automatically. Use this command whenever you need to fetch the actual image/file bytes or save them to a specific path.
This skill maps to the shortcut: lark-cli im +messages-resources-download (internally calls GET /open-apis/im/v1/messages/{message_id}/resources/{file_key}).
# Download an image (save to the current directory)
lark-cli im +messages-resources-download --message-id om_xxx --file-key img_v3_xxx --type image
# Download a file
lark-cli im +messages-resources-download --message-id om_xxx --file-key file_v3_xxx --type file
# Specify the output path
lark-cli im +messages-resources-download --message-id om_xxx --file-key img_v3_xxx --type image --output ./photo.png
# Download as a bot
lark-cli im +messages-resources-download --message-id om_xxx --file-key img_v3_xxx --type image --as bot
# Preview the request without executing it
lark-cli im +messages-resources-download --message-id om_xxx --file-key img_v3_xxx --type image --dry-run
| Parameter | Required | Description |
|---|---|---|
--message-id <id> |
Yes | Message ID (om_xxx format) |
--file-key <key> |
Yes | Resource key (img_xxx or file_xxx) |
--type <type> |
Yes | Resource type: image or file |
--output <path> |
No | Output path (relative paths only; .. traversal is not allowed; defaults to file_key as the file name). File extension is automatically added based on Content-Type if not provided |
--as <identity> |
No | Identity type: user (default) or bot |
--dry-run |
No | Print the request only, do not execute it |
When downloading large files, the command automatically uses HTTP Range requests for reliable chunked downloading:
| Behavior | Details |
|---|---|
| Probe chunk | First 128 KB to detect file size and Content-Type |
| Chunk size | 8 MB per subsequent request |
| Workers | Single-threaded sequential download (ensures reliability) |
| Retries | Up to 2 retries for transient request failures, with exponential backoff |
Benefits:
file_key SourcesDifferent resource markers in message content correspond to different file_key and type values:
| Message Type | Marker in Content | file_key Format |
--type |
|---|---|---|---|
| Image | img_xxx |
img_xxx |
image |
| File | file_xxx |
file_xxx |
file |
| Audio | file_xxx |
file_xxx |
file |
| Video | file_xxx |
file_xxx |
file |
# Step 1: Fetch messages and find one containing an image
lark-cli im +chat-messages-list --chat-id oc_xxx
# In the response you see: { "msg_type": "image", "content": "{\"image_key\":\"img_v3_xxx\"}" }
# Step 2: Download the image
lark-cli im +messages-resources-download --message-id om_xxx --file-key img_v3_xxx --type image
| Symptom | Root Cause | Solution |
|---|---|---|
| Download failed | file_key does not match the message_id |
Make sure the file_key came from that message's content |
| Hit error code 234002 or 14005 | No permission, not missing API scope | no access to this chat or file was deleted — do not retry, return the error to the user |
| Permission denied | im:message:readonly is not authorized |
Run auth login --scope "im:message:readonly" |
| File size mismatch | Chunked download integrity check failed | Network instability during download; retry the command |
| Content-Range error | Server returned invalid range header | Transient API issue; retry the command |