# Media

> Upload media assets and get back dp:// references.

## Upload media

<EndpointHeader method="POST" path="/media" />

Uploads one or more files and returns a `dp://` reference per file for use in `POST /jobs` datapoints.

<DocCallout type="note" title="File size limit">
Each file must be **20 MiB or smaller** (`20,971,520` bytes). This is a fixed platform-wide limit — it applies per file, not per request. Larger uploads are rejected with `413` and the error code `media_too_large`; the response body echoes the ceiling in bytes as `max_bytes`.
</DocCallout>

### Request

Multipart form-data with one or more `files` fields:

```
Content-Type: multipart/form-data

--boundary
Content-Disposition: form-data; name="files"; filename="video_a.mp4"
Content-Type: video/mp4

<binary>
--boundary
Content-Disposition: form-data; name="files"; filename="video_b.mp4"
Content-Type: video/mp4

<binary>
--boundary--
```

Files in a batch are processed **sequentially**, and there is **no partial rollback**: if the third file in a batch fails, the first two are already stored and keep their references. The whole batch is handled within a single request, so keep batches modest rather than sending very large numbers of files at once.

### Response (`200 OK`)

```json
{
  "media": [
    {
      "filename": "video_a.mp4",
      "media_id": "b6a1cd3f-1234-4abc-9def-0123456789ab",
      "media_ref": "dp://b6a1cd3f1234/video_a.mp4",
      "type": "video",
      "size_bytes": 2457623,
      "url": "/media/v2/b6a1cd3f-1234-4abc-9def-0123456789ab?cid=...&exp=1753280000&sig=..."
    }
  ]
}
```

<ParamTable
  params={[
    { name: "filename", type: "string", description: "The original filename as uploaded." },
    { name: "media_id", type: "string", description: "Stable identifier for the uploaded file. You normally pass `media_ref` to job creation; `media_id` is exposed for tooling that needs the raw identifier." },
    { name: "media_ref", type: "string", description: "Opaque dp:// URI. Pass verbatim to POST /jobs datapoints." },
    { name: "type", type: '"video" | "image" | "audio"', description: "Determined from the file extension (see Supported formats)." },
    { name: "size_bytes", type: "int", description: "Size of the stored file in bytes. Matches the bytes you sent, except for `.svg`, which is stored after sanitisation." },
    { name: "url", type: "string", description: "Signed, relative preview path for the uploaded file. Bound to your account and valid for roughly one hour, so you can render the asset immediately without a separate fetch. Not a permanent link — mint jobs from `media_ref`, not this URL." }
  ]}
/>

### Supported formats

| Type | Extensions |
|---|---|
| Image | `.png`, `.jpg`, `.jpeg`, `.webp`, `.avif`, `.gif`, `.svg`, `.heic`, `.heif` |
| Video | `.mp4`, `.webm`, `.mov` |
| Audio | `.mp3`, `.wav`, `.ogg`, `.m4a`, `.flac` |

The media **type is taken from the file extension**. The request `Content-Type` is only a cross-check:

- Extension not in the table above → `400` (`unsupported_media_extension`). Upload one of the supported formats.
- Extension and `Content-Type` disagree (e.g. a `.mp4` sent as `image/png`) → `400` (`media_type_mismatch`).
- A `Content-Type` the platform doesn't recognise is ignored — the extension still governs.

`.svg` uploads are sanitised on the way in (script vectors and unsafe references are stripped). An SVG that can't be parsed is rejected with `400` (`invalid_svg`).

Preview frames are generated for **video** only, and not at upload time — the poster frame is produced the first time the video is used in a job. The upload response's `url` always serves the full object; poster frames are served by `thumbnail_url` in `GET /media`.

<DocCallout type="note" title="Content review">
Uploads pass through a content-review step before they're accepted:

- Content that doesn't pass review may be rejected with `422` (`content_blocked`), with a generic reason.
- Media that can't be processed (corrupt or otherwise unreadable input) → `400` (`invalid_media`).
- If review is temporarily unavailable → `503` with a `Retry-After` header. Wait the indicated number of seconds and retry the same upload.
</DocCallout>

### Example

<CodeTabs>
  <CodeTab lang="curl" label="curl">
```bash
curl -X POST https://api.trydatapoint.com/data-labelling/v1/media \
  -H "X-API-Key: $DATAPOINT_KEY" \
  -F "files=@video_a.mp4" \
  -F "files=@video_b.mp4"
```
  </CodeTab>
  <CodeTab lang="python" label="Python">
```python
import requests, os

with open("video_a.mp4", "rb") as a, open("video_b.mp4", "rb") as b:
    r = requests.post(
        "https://api.trydatapoint.com/data-labelling/v1/media",
        headers={"X-API-Key": os.environ["DATAPOINT_KEY"]},
        files=[("files", a), ("files", b)],
    )
    r.raise_for_status()
    refs = [item["media_ref"] for item in r.json()["media"]]
```
  </CodeTab>
  <CodeTab lang="node" label="Node.js">
```javascript
import fs from "node:fs";

const form = new FormData();
form.append("files", new Blob([fs.readFileSync("video_a.mp4")]), "video_a.mp4");
form.append("files", new Blob([fs.readFileSync("video_b.mp4")]), "video_b.mp4");

const res = await fetch(
  "https://api.trydatapoint.com/data-labelling/v1/media",
  {
    method: "POST",
    headers: { "X-API-Key": process.env.DATAPOINT_KEY },
    body: form,
  }
);
const { media } = await res.json();
```
  </CodeTab>
</CodeTabs>

### Error cases

| Status | Error code | Cause |
|---|---|---|
| `400` | `unsupported_media_extension` | The file extension isn't supported. |
| `400` | `media_type_mismatch` | The extension and the declared `Content-Type` disagree. |
| `400` | `invalid_svg` | An `.svg` upload couldn't be parsed. |
| `400` | `invalid_media` | The file couldn't be processed (corrupt or unreadable). |
| `401` | — | Missing or invalid API key. |
| `413` | `media_too_large` | A file exceeds the 20 MiB limit; the body carries `max_bytes`. |
| `422` | `content_blocked` | The file didn't pass content review. |
| `429` | — | Rate limit exceeded. |
| `503` | — | Content review is temporarily unavailable; retry after `Retry-After` seconds. |

## List media

<EndpointHeader method="GET" path="/media" />

Lists your account's media — both files you uploaded through `POST /media` and media the platform fetched from direct URLs in your jobs — newest first. Paginated.

### Query parameters

<ParamTable
  params={[
    { name: "page", type: "int", required: false, default: "1", description: "1-based page number." },
    { name: "per_page", type: "int", required: false, default: "50", description: "Items per page, between 1 and 100." }
  ]}
/>

### Response (`200 OK`)

```json
{
  "media": [
    {
      "media_id": "b6a1cd3f-1234-4abc-9def-0123456789ab",
      "filename": "video_a.mp4",
      "media_ref": "dp://b6a1cd3f1234/video_a.mp4",
      "type": "video",
      "size_bytes": 2457623,
      "moderation_status": "allowed",
      "created_at": "2026-07-23T18:11:04Z",
      "url": "/media/v2/b6a1cd3f-1234-4abc-9def-0123456789ab?cid=...&exp=1753280000&sig=...",
      "thumbnail_url": "/media/v2/b6a1cd3f-1234-4abc-9def-0123456789ab?cid=...&exp=1753280000&sig=...&preview=1"
    }
  ],
  "total": 1,
  "page": 1,
  "per_page": 50
}
```

<ParamTable
  params={[
    { name: "media", type: "array", description: "Media items on this page, newest first." },
    { name: "total", type: "int", description: "Total number of media items across all pages." },
    { name: "page", type: "int", description: "The page you requested." },
    { name: "per_page", type: "int", description: "The page size in effect." }
  ]}
/>

Each item in `media`:

<ParamTable
  params={[
    { name: "media_id", type: "string", description: "Stable identifier for the file." },
    { name: "media_ref", type: "string", description: "The dp:// reference to pass to POST /jobs. Null for media the platform fetched from a direct URL in a job — only files uploaded through POST /media carry a dp:// reference." },
    { name: "filename", type: "string", description: "The original upload name, recovered from the reference. Falls back to the `media_id` when the row has no dp:// reference (media fetched from a direct URL)." },
    { name: "type", type: '"video" | "image" | "audio"', description: "The media type." },
    { name: "size_bytes", type: "int", description: "Stored size in bytes." },
    { name: "moderation_status", type: "string", description: "Availability of the file: `allowed` means it's ready to serve and preview; while it is `pending` (still in review) or if it was not accepted, the preview URLs won't resolve." },
    { name: "created_at", type: "string", description: "Upload timestamp (ISO 8601)." },
    { name: "url", type: "string", description: "Signed, relative preview path, bound to your account and valid for roughly one hour. Only resolves once `moderation_status` is `allowed`." },
    { name: "thumbnail_url", type: "string", description: "Signed preview path for the poster frame (videos). Falls back to the full object when no thumbnail exists; same availability rules as `url`." }
  ]}
/>

<DocCallout type="note" title="References are account-scoped and permanent">
A `dp://` reference resolves only for the account that uploaded it, and only on an exact match — you can't reference another account's media. Uploads **cannot be deleted through the API**. When you reference an uploaded file in a job by its `dp://` ref, its media type is already known from the upload, so you don't need to send a `type`. For datapoints that point at a direct URL, `type` is inferred from the URL's file extension; send `type` explicitly when the URL has no recognisable extension (e.g. query-string or content-negotiated URLs), otherwise the job is rejected with `400` (`unsupported_media_extension`).
</DocCallout>

## Next

- [Media handling concepts](/docs/media): how `dp://` refs are served end-to-end
- [Task types](/docs/task-types): where to plug media refs into datapoints
