# Upload media

Add images and videos to the library and attach them to posts.


Posts refer to media by id. Add a file to your library first, then pass the returned `media.id` as `mediaId` in `POST /posts`.

## Import from a URL (up to 25 MB)

```bash
curl -s -X POST "$CH_API/media" \
  -H "Authorization: Bearer $CH_KEY" -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/launch.png" }'
```

The URL must be public `https`. CreatorHyve downloads it, checks that the bytes really are the declared type (JPEG, PNG, WebP, GIF, MP4, MOV or WebM), stores it, and answers:

```json
{ "media": { "id": "9d3c...", "url": "https://storage.creatorhyve.com/uploads/...", "type": "image" } }
```

## Upload a large file

1. `POST /media` with `{ "action": "init", "type": "video/mp4", "size": 52428800 }` returns an `upload_url` and a `key`.
2. `PUT` the file to `upload_url` with the same `Content-Type` header.
3. `POST /media` with `{ "action": "complete", "key": "<key>", "filename": "launch.mp4" }` verifies the file and returns the `media` object.

Images may be up to 50 MB and videos up to 500 MB, within your plan's storage. Repeating `complete` for the same key returns the same item.

