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

# Uploading media

> How to upload images and videos, track their processing state, and attach them to scheduled posts using the API.

Posts across all platforms attach media by reference. This guide walks through the media lifecycle — uploading a file, verifying it, and attaching it to a scheduled post — plus the URL-transloading alternative for remote files.

## How media attachment works

Media is uploaded independently of posts. An upload returns a **media ID**, which you reference in `base.media` (or a channel override) when creating a post:

```json theme={null}
{
  "postDetails": {
    "base": {
      "text": "Launching today!",
      "timestamp": "2025-02-01T14:00:00Z",
      "media": ["md_abc123"]
    },
    "channels": ["ch_ig_brand"]
  }
}
```

A post attaches its media at creation time, so the media must be `LIVE` (verified and ready) before you create the post.

## Media statuses

| Status | Meaning |
| - | - |
| `PENDING` | Upload URL issued, file not yet confirmed in storage |
| `PROCESSING` | Reserved for server-side processing — treat as not ready |
| `LIVE` | Verified in storage, ready to attach to posts |
| `FAILED` | Verification or probing failed |
| `DELETED` | Removed |

## Step 1: Request a presigned upload URL

**1. Request an upload URL**

```bash theme={null}
curl -X POST "https://posttu.com/api/media/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filename": "launch-banner.jpg",
    "contentType": "image/jpeg",
    "extension": "jpg",
    "sessionId": "sess_v0Kps9Bgnk2",
    "bytes": 248320,
    "meta": { "altText": "Product launch banner" }
  }'
```

The response contains a presigned URL and the media ID:

```json theme={null}
{
  "url": "https://storage.posttu.com/posttu/org/…?X-Amz-Algorithm=…",
  "method": "PUT",
  "key": "posttu/org/org_abc123/md_v0Kps9Bgnk2.jpg",
  "expiresIn": 3600,
  "maxSize": 5242880000,
  "mediaId": "md_v0Kps9Bgnk2"
}
```

The media row is created in `PENDING` state. URLs expire after **1 hour** and accept files up to **\~5 GB** — for larger files, split your content or use multiple assets.

**2. Upload the file bytes**

`PUT` the raw file directly to the presigned URL. No API key is needed — the URL itself is the authorization:

```bash theme={null}
curl -X PUT "PRESIGNED_URL" \
  -H "Content-Type: image/jpeg" \
  --data-binary @/path/to/launch-banner.jpg
```

If the upload is interrupted, request a fresh URL (the presigned one can't be renewed).

**3. Finalize the upload**

Finalizing verifies the file landed in storage, probes it for dimensions, duration, and format, and marks it `LIVE`. It also corrects the MIME type and video flag from the actual file contents:

```bash theme={null}
curl -X POST "https://posttu.com/api/v1/media/finalize" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mediaIds": ["md_v0Kps9Bgnk2"] }'
```

Each asset is reported individually:

```json theme={null}
{
  "success": true,
  "data": [
    {
      "id": "md_v0Kps9Bgnk2",
      "exists": true,
      "status": "LIVE",
      "stats": {
        "size": 248320,
        "format": "jpg",
        "mime_type": "image/jpeg",
        "media_type": "image",
        "width": 1920,
        "height": 1080
      }
    }
  ]
}
```

Batch up to **50 media IDs** per call. A `404` response lists `missingIds` — assets that were never uploaded or belong to another workspace. An asset can also report `status: "FAILED"` (probe error); re-upload and finalize again in that case.

**4. Attach to a post**

Reference the media IDs in `base.media` or channel overrides when [creating a post](https://docs.posttu.com/guides/scheduling-posts.md):

```bash theme={null}
curl -X POST "https://posttu.com/api/v1/posts/create" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "postDetails": {
      "base": {
        "text": "Launching today!",
        "timestamp": "2025-02-01T14:00:00Z",
        "media": ["md_v0Kps9Bgnk2"]
      },
      "channels": ["ch_ig_brand"]
    },
    "isDraft": false
  }'
```

The same media ID can be attached to multiple posts across platforms.

## Checking upload readiness

If you need to confirm an asset is ready before creating posts (for example, after a retry), poll its status:

```bash theme={null}
curl "https://posttu.com/api/media/md_v0Kps9Bgnk2/status" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```json theme={null}
{ "status": "LIVE" }
```

Treat both `PENDING` and `PROCESSING` as "not ready" in your polling loop. `PENDING` assets self-heal: if the file is already in storage, the status check promotes them to `LIVE`.

## Alternative: URL transloading for bulk imports

If your files live at public URLs, skip the upload entirely. The [bulk upload](https://docs.posttu.com/guides/bulk-uploads.md) endpoint accepts a `mediaUrl` per post, and a background worker downloads the file, registers it as media, links it to the post, and schedules it:

```bash theme={null}
curl -X POST "https://posttu.com/api/v1/posts/bulk" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "posts": [
      {
        "text": "Stunning visuals",
        "platform": "INSTAGRAM",
        "channelId": "ch_ig_brand",
        "mediaUrl": "https://example.com/visual.png",
        "timestamp": "2025-02-01T14:00:00Z"
      }
    ]
  }'
```

While transloading runs, the post sits in `PROCESSING` status; it moves to `SCHEDULED` when the media is attached, or `FAILED` with a `failureReason`. Track progress with [get bulk upload status](https://docs.posttu.com/api-reference/posts/bulk-upload-status.md).

## Error handling

| Status | Cause | Recovery |
| - | - | - |
| `400` | Invalid payload (filename, MIME type, missing fields) | Fix the request body |
| `401` | Missing or invalid API key | Check the `Authorization` header |
| `403` | API key lacks the required scope | Grant `posts:write` or `posts:read` |
| `404` | Media ID unknown or not in your workspace | Verify the media ID |
| `429` | Rate limit exceeded | Back off using `Retry-After` |

## Cleanup

When a post is deleted or rejected, media attached only to that post is cleaned up automatically. Media attached to multiple posts (or to none) remains in your library.


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