> ## 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.

# Upload media

> Get a presigned URL to upload a media file directly to storage.

# Upload media

`POST /api/media/upload`

Request a presigned upload URL, then `PUT` the raw file bytes to the returned URL. The media record is created immediately in `PENDING` state; call [finalize](https://docs.posttu.com/api-reference/media/finalize-media.md) once the upload completes to verify the file and mark it `LIVE`.

## Required Scope

`posts:write`

## Request Body Parameters

**filename** `string` *required*

Original file name (1–255 characters, alphanumeric, dashes, underscores, dots, and spaces).

**contentType** `string` *required*

MIME type, e.g. `image/jpeg` or `video/mp4`.

**extension** `string` *required*

File extension without the dot, e.g. `jpg`, `png`, `mp4`.

**sessionId** `string` *required*

Groups related uploads together. Generate a unique string per upload batch (e.g. `sess_v0Kps9Bgnk2...`).

**bytes** `number` *required*

File size in bytes.

**id** `string`

Optional client-supplied media ID. Omit to let the server generate one.

**meta** `object`

Optional metadata stored with the media asset.

**meta properties**

**meta.altText** `string`

Alt text for accessibility.

**meta.isVideo** `boolean`

Whether the file is a video.

**meta.duration** `number`

Video duration in seconds.

**meta.isNsfw** `boolean`

Marks the media as NSFW.

## Request Example

```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" }
  }'
```

## Response Example

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

## Upload the file

`PUT` the raw bytes to the returned `url` with the same `Content-Type`. The URL expires after 1 hour and accepts files up to `maxSize` (\~5 GB).

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

## Next step

Once the `PUT` succeeds, call [finalize media](https://docs.posttu.com/api-reference/media/finalize-media.md) to verify the upload, extract dimensions and duration, and mark the asset `LIVE`.

## Error Responses

### Invalid Payload (`400 Bad Request`)

```json theme={null}
{
  "error": "Validation failed",
  "details": { "contentType": ["Invalid content type format"] }
}
```

### Unauthorized (`401 Unauthorized`)

```json theme={null}
{
  "error": "Internal server error"
}
```

Returned when no valid API key or session is present.


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