---
title: Download Images & Attachments
description: List the images, audio, video and files stored for a document, and download them through short-lived links.
type: guide
status: stable
updated: 2026-12-03
url: /en/docs/attachments
markdown: /en/docs/attachments.md
---

## Data Access Path

Recommended reading order, not a record of completed steps. Optional steps can be skipped.

1. [Get an API Key](/en/docs/authentication)
2. [Make Your First Query in 5 Minutes](/en/docs/quickstart)
3. [Keyword Search](/en/docs/search)
4. [Browse by User, Topic, Tag & Category](/en/docs/browse) (optional)
5. [Read Content & Versions](/en/docs/documents)
6. [Download Images & Attachments](/en/docs/attachments) (optional) ← current page
7. [Production Checklist](/en/docs/production)

**Before You Start**：Read content first; for uploaded images/files confirm assets permission, or skip if no downloads are needed.

# Download Images & Attachments

For some documents, MarsYoo has stored copies of images, audio, video or files. By the end of this page you can list and download them.

A document's `assets` are original platform links and may stop working. Attachments here are copies we stored and can download reliably. Not every original link has a copy.

Requires `assets` field access.

## List attachments [#list]


```bash
curl -sS "$WHALE_BASE_URL/v1/documents/$DOCUMENT_ID/attachments?limit=50" \
  -H "Authorization: Bearer $WHALE_API_KEY"
```



```json
{
  "attachments": [
    {
      "asset_id": "asset_01K...",
      "source_platform": "xiaohongshu",
      "role": "cover",
      "origin_url": "https://source.example.com/cover.jpg",
      "filename": "cover.jpg",
      "media_type": "image",
      "mime_type": "image/jpeg",
      "size_bytes": 248133,
      "status": "ready",
      "created_at": "2026-10-14T08:00:00Z"
    }
  ],
  "next_cursor": ""
}
```


| Field | Meaning |
| --- | --- |
| `asset_id` | Attachment ID, used to download |
| `media_type` | `image`, `video`, `audio`, `document` or `other` |
| `role` | `cover` (at most one per document), `inline` (image in the body), `gallery` (one item in a gallery), `media` (the video or audio itself) |
| `origin_url` | The original platform link, for provenance only |
| `status` | Always `ready` in the list; only fully stored files are listed |

- `limit` is 1 to 100, default 50.
- When `next_cursor` isn't empty, pass it as `after` for the next page.
- An empty list can mean no files were stored, or storage is still in progress.
- Only the current version's attachments are available.

To show a cover, download the attachment with `role` `cover`; it's more reliable than `document.cover.url` or `origin_url`.

## Download a file [#download]

Get a download link first, then download:


```bash
ASSET_ID="asset_01K..."

DOWNLOAD_URL=$(curl -sS "$WHALE_BASE_URL/v1/documents/$DOCUMENT_ID/attachments/$ASSET_ID/download" \
  -H "Authorization: Bearer $WHALE_API_KEY" | jq -er '.url')

curl -sS -o cover.jpg "$DOWNLOAD_URL"
```


The endpoint returns `{"url": "...", "expires_in": 300}`:

- The link is valid for 300 seconds; request a new one after that.
- Don't send your API key when downloading.
- Don't store the link long-term or write it to public logs.

## When something fails [#errors]

An attachment still being stored returns `409 attachment_incomplete`; retry later. Other errors: [Error codes](/en/docs/errors).

## Check and Continue

**Completion Check**：Retrieve and download available files without persisting short-lived URLs; next configure limits, retries and error handling.

Previous step：[Read Content & Versions](/en/docs/documents)

**Recommended Next Step**：[Production Checklist](/en/docs/production)
