> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get files from AI chats into PostSyncer

> Put a photo, video or document from a chat on a post: ChatGPT attachments, upload links the user opens, and curl for agents that run commands.

An AI app often has the file the user wants to post, but an MCP tool call carries text, not the file. How the file gets to PostSyncer depends on the app:

| The app | How the file gets in |
| - | - |
| ChatGPT | The user attaches the file to the message. `upload-media-file` takes it as `file`. |
| Claude and other chat apps | The AI makes an upload link. The user opens it and drops the file. |
| Agents that run commands (Claude Code, Codex, Cursor, OpenClaw and others) | The AI makes an upload link and sends the file to it with curl. |
| Your own code, with an API key | [Upload a file](https://docs.postsyncer.com/api-reference/media/upload-file.md) straight to the library. |

Each way ends with media library ids, which go in a post's `content[].media`. A file already at a public link needs none of this: give the link to `upload-media-from-url`, or put it in the post. See [Add media to posts](https://docs.postsyncer.com/guides/media.md).

## ChatGPT: attach the file

In ChatGPT, the user attaches a photo, video or document to the message and asks for the post. ChatGPT passes the file to `upload-media-file` as `file`, filled in by ChatGPT itself: a private download link, the file's id, and its name and type when ChatGPT has them. PostSyncer downloads the file and stores it like any upload, then answers one `media` item with its `id`.

* A file can be up to 500 MB, and the download has 75 seconds.
* The type rules are those of [Upload a file](https://docs.postsyncer.com/api-reference/media/upload-file.md). A file of another type is refused and nothing is stored.
* When the download fails, the error names the file, never the link. Most errors ask the user to attach it again: for example "ChatGPT's link to spring-launch.mp4 didn't work (HTTP 403). Attach the file again and retry." A download that takes too long says to try again or attach a smaller file, and a file over 500 MB says it's too big. A file that keeps taking too long goes through an upload link instead.

`file_base64` (with `filename`) is only for a file whose bytes the AI has itself, such as one it read from disk. The AI never retypes a file it only sees in the chat: any attached file an app can't pass as `file`, whatever its size, goes through an upload link.

## Claude and other chat apps: open an upload link

**1. Make the link**

The AI calls `create-media-upload-link` with `workspace_id`, and a `folder_id` if the files should go in a folder. Without MCP, it's [Create an upload link](https://docs.postsyncer.com/api-reference/media/upload-link.md) (`POST /media/upload-links`, `media:create`).

**2. Give the user the link**

The answer's `url` is a page like `https://app.postsyncer.com/upload/Hk3vQ9wLr2TnB7xYc4ZpM8dJf6sAe1Gu5oKi0WqXt2yNb7Rm`. The AI gives it as a link to click and asks the user to say when the upload is done.

**3. The user drops the files**

The page works on any device, with no PostSyncer sign-in. It names the workspace and folder, and how many more files the link takes and until when. The user drops files on it or taps **Choose files**. Each file shows its progress, and big files go in parts on their own. When every file is done, the page says: "Uploaded. Go back to your AI app and tell it the upload is done."

**4. Read the link**

The AI calls `get-media-upload-link` with the link's `id` and uses the media ids it gets. See [Read the link](#read-the-link).

The link only uploads. Whoever has it can add files to that workspace until it expires or is full, and can't see the library, the posts or anything else. Give it only to the person who has the file.

## Agents that run commands: send the file with curl

An agent that can run commands on the user's computer makes the link the same way, then sends the file to the answer's `upload_url` itself. No API key goes with it: the link is enough.

### A file up to 95 MB

One request, with the whole file as `file`:

```bash theme={null}
curl -X POST "https://postsyncer.com/api/media-upload-links/Hk3vQ9wLr2TnB7xYc4ZpM8dJf6sAe1Gu5oKi0WqXt2yNb7Rm/files" \
  -F "file=@latte-art.jpg"
```

It answers `201`:

```json theme={null}
{
  "status": "upload_complete",
  "media": {
    "id": 9062,
    "workspace_id": 12,
    "folder_id": 41,
    "name": "latte-art.jpg",
    "url": "https://cdn.postsyncer.com/examples/latte-art.jpg",
    "mime_type": "image/jpeg",
    "size": 482113,
    "is_processing": false,
    "type": "image",
    "ai_generated_id": null,
    "is_reference": false,
    "progress": 100,
    "alt": null,
    "duration_seconds": null
  }
}
```

A file sent twice is stored twice: when an answer gets lost, [read the link](#read-the-link) before you send the file again. A request over 95 MB answers `422` (below), and a much bigger one can be cut off before PostSyncer reads it, with a `413` and no `message`. Either way, send the file in chunks.

### A bigger file, in chunks

A file over 95 MB goes in chunks of up to 25 MB, one request each. Every request carries:

| Field | Value |
| - | - |
| `file` | The chunk's bytes, up to 25 MB. |
| `chunk_index` | `0` for the first chunk, then `1`, `2` and on. |
| `total_chunks` | How many chunks the file has, up to 2,000. |
| `file_id` | A UUID you make for this file. The same on every chunk of the file, and new for each file. |
| `file_name` | The file's name, with its extension. |
| `mime_type` | The file's type, like `video/mp4`. |
| `file_size` | Optional: the whole file's size in bytes. A file over 500 MB is then refused before any chunk is kept. |

Each chunk but the last answers `200` with `"status": "chunk_uploaded"` and `data` (`chunk_index`, `uploaded_chunks`, `total_chunks`, `progress` in percent). The last answers `200` with `"status": "upload_complete"` and the `media`, as above. Sending a chunk again, after an answer got lost, is safe: a finished file answers with its `media` again, never a second copy.

> [!WARNING]
>
> Make a new `file_id` for every file. On the same link, a `file_id` that already finished a file answers with that first file, and the new file isn't stored.

This loop sends one file in 20 MB chunks, in bash or zsh. Put the link's `upload_url` in `UPLOAD_URL`. Where there's no `uuidgen`, `cat /proc/sys/kernel/random/uuid` makes a UUID on Linux. `file` reads the type from the bytes; if it says `application/octet-stream`, set `MIME` yourself, like `video/mp4`.

```bash theme={null}
UPLOAD_URL="https://postsyncer.com/api/media-upload-links/Hk3vQ9wLr2TnB7xYc4ZpM8dJf6sAe1Gu5oKi0WqXt2yNb7Rm/files"
FILE="spring-launch.mp4"

FILE_ID=$(uuidgen)
MIME=$(file --mime-type -b "$FILE")
SIZE=$(wc -c < "$FILE" | tr -d ' ')

split -b 20m "$FILE" "$FILE_ID.part."
TOTAL=$(ls "$FILE_ID".part.* | wc -l | tr -d ' ')

i=0
for PART in "$FILE_ID".part.*; do
  curl --fail-with-body -sS -X POST "$UPLOAD_URL" \
    -F "file=@$PART" \
    --form-string "chunk_index=$i" \
    --form-string "total_chunks=$TOTAL" \
    --form-string "file_id=$FILE_ID" \
    --form-string "file_name=$(basename "$FILE")" \
    --form-string "mime_type=$MIME" \
    --form-string "file_size=$SIZE" || { echo; echo "Stopped at chunk $i ($PART), file_id $FILE_ID"; break; }
  echo
  i=$((i + 1))
done

if [ "$i" -eq "$TOTAL" ]; then rm "$FILE_ID".part.*; fi
```

`split` names the chunks in order (`.part.aa`, `.part.ab` and on), so the loop sends them in order. The last answer printed holds the `media`, and the chunk files are then deleted. When a request fails, the loop stops, prints the answer and the chunk it stopped at, and keeps the chunk files: see [Errors](#errors). To finish the file, send that chunk and the ones after it with the same `file_id`, `total_chunks` and their own `chunk_index`. Or delete the chunk files and run the loop again: that starts the file over with a new `file_id`.

### The two addresses

Both come from the create answer. Use them as they are.

| Address | What it is |
| - | - |
| `url`: `https://app.postsyncer.com/upload/{code}` | The page the user opens. |
| `upload_url`: `https://postsyncer.com/api/media-upload-links/{code}/files` | `POST`, `multipart/form-data`: the upload above. |

`{code}` is the link's code, the same in both. The page also reads `GET https://postsyncer.com/api/media-upload-links/{code}`, which answers what it shows: `workspace_name`, `folder_name` (or `null`), `expires_at`, `max_files`, `files_uploaded` and `max_file_size` (in bytes), or the same `404`, `410` and `403` as an upload.

## Read the link

When the user says the upload is done, read the link by its `id`: `get-media-upload-link` in MCP, or [Get an upload link](https://docs.postsyncer.com/api-reference/media/upload-link-get.md) (`GET /media/upload-links/{upload_link_id}`, `media:read`).

```json theme={null}
{
  "upload_link": {
    "id": 318,
    "expires_at": "2030-03-15T10:00:00+00:00",
    "expired": false,
    "max_files": 10,
    "files_uploaded": 1,
    "media": [
      {
        "id": 9062,
        "workspace_id": 12,
        "folder_id": 41,
        "name": "latte-art.jpg",
        "url": "https://cdn.postsyncer.com/examples/latte-art.jpg",
        "mime_type": "image/jpeg",
        "size": 482113,
        "is_processing": false,
        "type": "image",
        "ai_generated_id": null,
        "is_reference": false,
        "progress": 100,
        "alt": null,
        "duration_seconds": null
      }
    ]
  }
}
```

* Put each `media[].id` in a post's `content[].media`.
* `media` lists the files the link took that are still in the library, in the order they arrived. `files_uploaded` counts every file the link took, including any deleted from the library since, so it can be more than the items in `media`.
* An empty `media` with `files_uploaded` at `0` means nothing arrived yet: ask the user whether the upload finished.
* This answer never has `url` or `upload_url`. Only the create answer gives them, so keep them until the upload is done. A lost link can't be found again: make a new one.

## Limits

| Limit | Value |
| - | - |
| A link works for | 60 minutes after it's made (`expires_at`) |
| Files a link takes | 10 |
| One file | 500 MB |
| One request without chunk fields | 95 MB |
| One chunk | 25 MB, and up to 2,000 chunks a file |
| All the chunks a link takes | 10 files of 500 MB (5 GB), plus 1 GB for chunks sent again |
| Uploads | 300 requests a minute for one link, and 600 a minute from one address across links |
| The page's lookup | 60 requests a minute from one address |
| Types | Pictures (JPEG, PNG, GIF, WebP), videos (MP4, MOV, WebM) and documents (PDF, DOC, DOCX, PPT, PPTX). Documents publish to LinkedIn only. |

An expired or full link keeps the files it took: they stay in the library and in the link's `media`.

## Errors

Every refusal has a `message` in plain words, which the page shows as it is. A refusal about the file or a field (`422` with `errors`) has the same words under `errors.file` or the field's name. Nothing is kept from a refused file.

| Status | `message` | What to do |
| - | - | - |
| 404 | This upload link isn't valid. Ask your AI app for a new one. | The link's code is wrong or cut off. Check `upload_url`, or make a new link. |
| 410 | This upload link has expired. Ask your AI app for a new one. | Make a new link. |
| 403 | This upload link no longer works. Ask your AI app for a new one. | The person who made the link can no longer add media to the workspace: their role changed, they left it, or their account was switched off. Make a new link as someone who can. |
| 422 | This link already took 10 files. Ask your AI app for a new link. | Make a new link for more files. |
| 422 | This link took as much as it can. Ask your AI app for a new link. | The link took all the chunks it can: 10 files of 500 MB, plus 1 GB for chunks sent again. Make a new link. |
| 422 | This type of file can't be posted. Upload a photo (JPG, PNG, GIF or WebP), a video (MP4, MOV or WebM) or a document (PDF, DOC, DOCX, PPT or PPTX). | Send another type. A chunk without `mime_type` gets this too. |
| 422 | One request takes a file up to 95 MB. Send a bigger file in chunks: see [https://docs.postsyncer.com/guides/files-from-ai-chats#a-bigger-file-in-chunks](https://docs.postsyncer.com/guides/files-from-ai-chats.md#a-bigger-file-in-chunks) | Send it [in chunks](#a-bigger-file-in-chunks). |
| 422 | The file may not be greater than 500.00 MB. | The file is over 500 MB: send a smaller one. |
| 422 | A field's own words, under `errors` | A chunk field is missing or wrong, like a `file_id` that isn't a UUID or a chunk over 25 MB. Fix it and send the chunk again. |
| 429 | Too many uploads at once. Wait a minute, then try again. | Wait the `Retry-After` seconds, then send that request again. |
| 500 | Upload failed. Try again in a moment. | Send that request again. |

## Related

> [card] [Create an upload link](https://docs.postsyncer.com/api-reference/media/upload-link.md)
>
> `POST /media/upload-links` and its answer.

> [card] [Add media to posts](https://docs.postsyncer.com/guides/media.md)
>
> Links, uploads and library ids on posts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.