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

# Upload media

> Add photos and videos to the library, then attach them to posts.

> [tab] CLI
>
> The CLI does every step for you:
>
> ```bash theme={"system"}
> postinger media upload photo.jpg video.mp4 https://example.com/banner.png
> ```
>
> It checks each file, uploads it (in parts when it's large) and prints the media ID to pass to `--media`.

> [tab] API
>
> **1. Start the upload**
>
> Tell Postinger what you're sending. Width, height and duration are yours to measure: the platform rules are checked against them.
>
> ```bash theme={"system"}
> curl https://api.postinger.dev/v1/media \
>   -H "Authorization: Bearer $POSTINGER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{ "fileName": "clip.mp4", "contentType": "video/mp4", "size": 52428800, "width": 1080, "height": 1920, "durationSeconds": 42.5 }'
> ```
>
> The answer has the `media` (with its `id`) and `upload` instructions.
>
> **2. Send the bytes to storage**
>
> * If `upload.url` is set, `PUT` the whole file there with `upload.headers`.
> * Otherwise, split the file into `upload.partSize` pieces and `PUT` each to its `upload.parts[].url`, in `partNumber` order (part 1 starts at byte 0).
>
> Don't send your API key to storage. A `PUT` of the same bytes is safe to repeat.
>
> **3. Complete the upload**
>
> ```bash theme={"system"}
> curl -X POST https://api.postinger.dev/v1/media/MEDIA_ID/complete \
>   -H "Authorization: Bearer $POSTINGER_API_KEY"
> ```
>
> Postinger checks what arrived. It's safe to call again.
>
> > [!TIP]
> >
> > For a video, the answer may also carry `poster` instructions: `PUT` a JPEG frame there, the same way, to choose the thumbnail. It's optional.
>
> The upload instructions expire at `expiresAt`.

> [tab] From a link
>
> If the file is already online at a public `https://` address, let Postinger fetch it:
>
> ```bash theme={"system"}
> curl https://api.postinger.dev/v1/media/from-url \
>   -H "Authorization: Bearer $POSTINGER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{ "url": "https://example.com/banner.jpg", "fileName": "banner.jpg" }'
> ```
>
> The media is ready when this answers. MCP adds media this way.

## Attach it

Pass the media IDs as `mediaIds` when you [create the post](https://docs.postinger.dev/guides/schedule-a-post.md), or `--media MEDIA_ID` with the CLI.


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