
# Start a direct upload

Start the direct upload flow. Use it for files over 100 MB, which [POST /media](/api/media/post-media) and page writes do not accept, and for any upload you want to be able to retry. It hands you URLs to upload the file to directly, up to your plan's per-file limit of 10 GB on a paid plan and 10 MB on the free plan.

The flow is three calls: initiate, upload to the URLs you get back, then [complete](/api/media/post-uploads-complete). Nothing appears in the media library until the complete call.

```sh
POST https://sitepaste.com/api/v1/public/uploads
```

Requires the `media` scope.

## Usage

```bash
curl -X POST https://sitepaste.com/api/v1/public/uploads \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fileName": "field-recording.mp4",
    "fileSize": 734003200,
    "mimeType": "video/mp4"
  }'
```

## Authorizations

| Header | Type | Required | Description |
|--------|------|----------|-------------|
| Authorization | string | Yes | Bearer token (`Authorization: Bearer sp_...`). Created in the dashboard under Account > Tokens. See [authentication](/api/authentication). |

## Body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| fileName | string | Yes | The original filename. Its extension decides whether the file type is allowed. |
| fileSize | integer | Yes | Size in bytes; must be positive. Decides direct vs multipart, and is checked against your plan's file and storage limits. |
| mimeType | string | Yes | The file's content type. A direct upload's PUT must send the same value as its `Content-Type`. |
| siteId | string | No | Site whose protection settings the file inherits, as a short ID or the literal `default`. Omitted, the default site's settings apply. |
| pageId | string | No | Page whose protection settings the file inherits, on top of the site's, as a short ID. It must be a page of the site the file inherits from: the one `siteId` names, or the default site when `siteId` is omitted. |

`note`, `highQuality`, `preserveMetadata`, and `folderId` are set on [complete](/api/media/post-uploads-complete), which is where the media record is created.

## Response

201 Created, with a `Location` header naming the upload. Files of 100 MB or less come back as a single URL to PUT the whole file to:

```json
{
  "id": "EuzZxavfYmFpraKp8aASLnzNA1NT",
  "presignedUrl": "https://...",
  "fileName": "f8e2a1b3c4d5.mp4"
}
```

Send the file body to `presignedUrl` with PUT, using the same `Content-Type` you declared. The URL is valid for one hour.

Larger files come back as a multipart upload, one upload URL per 25 MB part:

```json
{
  "id": "Um8ZBMuFXwQYTp_yiuJT0Hnck8RDZAEzpog",
  "fileName": "f8e2a1b3c4d5.mp4",
  "parts": [
    { "partNumber": 1, "presignedUrl": "https://..." },
    { "partNumber": 2, "presignedUrl": "https://..." }
  ]
}
```

PUT each 25 MB slice to its part URL, where the last part is whatever remains. Keep the `ETag` response header of each one, because [complete](/api/media/post-uploads-complete) needs them. Part URLs are valid for two hours. To walk away from a started multipart upload, [abort it](/api/media/delete-uploads-uploadid) so its parts are discarded.

Keep the `id`. It is how you [finish](/api/media/post-uploads-complete) or [abort](/api/media/delete-uploads-uploadid) the upload.

| Field | Type | Description |
|-------|------|-------------|
| id | string | The upload's id. Treat it as opaque. |
| presignedUrl | string | Direct only: the URL to PUT the whole file to. |
| parts | array | Multipart only: `partNumber` and `presignedUrl` per 25 MB part. |
| fileName | string | The name the file is given, not the one you sent. |

A direct upload carries `presignedUrl` and a multipart one carries `parts`, so check which of the two is present to know how to send the file.

## Errors

| Code | Meaning |
|------|---------|
| 402 | The file would exceed your storage quota. |
| 404 | The `siteId` names no site in this workspace, or the `pageId` names no page of the site the file inherits from. In a workspace with no default site, a `siteId` of `default` and a `pageId` sent without a `siteId` are refused with the code `no_default_site`. |
| 413 | The file exceeds your plan's per-file limit, or exceeds 100 MB on a plan without multipart. |
| 422 | `fileName`'s extension is not an allowed file type, or a field is missing or invalid, such as a `siteId` or `pageId` that is not a short ID. `fields` names the field at fault. |
| 503 | File storage is unavailable. Retry shortly. |

This call reserves nothing and spends nothing from the [upload budget](/api/overview#rate-limiting). The call that spends it is [complete](/api/media/post-uploads-complete).