# Uploading videos

This guide uploads a video file into your Livepush video library using the same calls,
in the same order, as the Livepush dashboard. Once uploaded, the video can be scheduled as
a [pre-recorded stream](/guides/pre-recorded-streams/).

An upload takes five calls across two hosts:

| Step | Call | Host |
| --- | --- | --- |
| 1 | [Get video storage specs](/videos/get-video-storage-specs/) | `octopus.livepush.io` |
| 2 | [Create a video upload URL](/videos/create-a-video-upload-url/) | `octopus.livepush.io` |
| 3 | [Create an upload session](/videos/create-an-upload-session/) | `vod-uploads-middleware-api.livepush.io` |
| 4 | [Upload a file to a session](/videos/upload-a-file-to-a-session/) | `vod-uploads-middleware-api.livepush.io` |
| 5 | [Register an uploaded video](/videos/register-an-uploaded-video/) | `octopus.livepush.io` |

The file itself goes to the upload middleware in step 4, which writes it to storage for
you. You never upload to the storage provider directly.

Every call, on both hosts, sends the same `Authorization: Bearer YOUR_API_TOKEN` header.
The token needs the `streams.videos.read` scope for step 1 and `streams.videos.write` for
the rest. See [Authentication](/guides/authentication/).

## 1. Find the storage zone

```bash
curl -X GET 'https://octopus.livepush.io/streams/me/videos/storage_specs' \
  -H 'Authorization: Bearer YOUR_API_TOKEN'
```

```json
{
  "canSelectStorage": false,
  "defaultStorageZone": null,
  "isMultipartUploadDisabled": true,
  "isGoogleDriveEnabled": false,
  "storageZones": [
    { "id": "zn_35hk0gxy_pr", "name": "Video Cloud Storage NS10", "host": "vod-ns10-cdn-livepush.akamaized.net", "isDefault": true },
    { "id": "zn_dg5dshe82", "name": "Optimized Storage", "host": "vod-scw-par-2.livepush.io" }
  ]
}
```

Pick the zone the same way the dashboard does:

1. If `defaultStorageZone` is set, use it.
2. Otherwise use the `id` of the `storageZones` entry with `isDefault: true`.

`defaultStorageZone: null`, `canSelectStorage: false` and `isMultipartUploadDisabled: true`
is the normal response for most accounts. None of it blocks uploading.

## 2. Create an upload URL

```bash
curl -X POST 'https://octopus.livepush.io/streams/me/videos/uploadurl' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "originalFilename": "morning-session.mp4",
    "type": "video/mp4",
    "size": 734003200,
    "zone": "zn_35hk0gxy_pr"
  }'
```

```json
{
  "id": "Xk2fP9qLm",
  "Key": "nsAbC123xY_/Xk2fP9qLm.mp4",
  "uploadUrl": "https://…storage endpoint…",
  "uploadType": "formdata",
  "uploadCredentials": { "key": "nsAbC123xY_/Xk2fP9qLm.mp4", "…": "signed form fields" },
  "zone": "zn_35hk0gxy_pr"
}
```

| Field | Value |
| --- | --- |
| `originalFilename` | The file's name. Its extension becomes the stored file's extension. |
| `type` | The file's MIME type, such as `video/mp4`. |
| `size` | The file's size in bytes. Checked against your plan before anything is allocated. |
| `zone` | The zone from step 1. **Required**: with `me` in the path, the call fails with a `500` without it. |

Use `me` in the path, as the dashboard does. Videos belong to your account, not to a
stream, so one upload can be scheduled on any of your streams.

`Key` is `<namespace>/<id>.<ext>` for most accounts; treat it as opaque and pass it back as
you received it.

**Keep the whole response.** Step 3 sends it back unchanged, and step 5 needs its `id`,
`Key` and `zone`. Do not send the file to the `uploadUrl` in this response: that is the
storage endpoint the middleware writes to, and the fields in `uploadCredentials` are for
the middleware to use.

### Plan limits

This is the call that enforces your plan's storage limits. When the file does not fit, it
fails with status `405` and one of these `error` codes, and `data.limit` holds the limit
that was hit:

| `error` | Meaning |
| --- | --- |
| `max_upload_size_reached` | The file is larger than your plan allows per file. |
| `max_storage_size_reached` | The file would take the library over your plan's total storage. |
| `max_upload_files_reached` | The library already holds as many videos as your plan allows. Delete some first. |

## 3. Create an upload session

Send the response from step 2, exactly as you received it, to the upload middleware:

```bash
curl -X POST 'https://vod-uploads-middleware-api.livepush.io/uploads/new' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "Xk2fP9qLm",
    "Key": "nsAbC123xY_/Xk2fP9qLm.mp4",
    "uploadUrl": "https://…storage endpoint…",
    "uploadType": "formdata",
    "uploadCredentials": { "key": "nsAbC123xY_/Xk2fP9qLm.mp4", "…": "signed form fields" },
    "zone": "zn_35hk0gxy_pr"
  }'
```

```json
{
  "uploadUrl": "https://vod-uploads-middleware-api.livepush.io/uploads/Qe8rT2pZx"
}
```

The returned `uploadUrl` is a session that lasts 24 hours and **accepts one upload
attempt**. Whatever happens in step 4, that session is used up; to retry, call this
endpoint again with the same body.

## 4. Upload the file

`PUT` the raw file bytes to the session URL, with your bearer token. The body is the file
itself, not a form and not JSON.

```bash
curl -X PUT 'https://vod-uploads-middleware-api.livepush.io/uploads/Qe8rT2pZx' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: video/mp4' \
  --data-binary '@morning-session.mp4'
```

```json
{ "success": true }
```

The middleware streams the file into storage as it arrives and answers only once the
whole file has been written. For a large file that is a long request: disable or raise
your HTTP client's timeout for this call. The dashboard sends files of every size this
way, in a single request.

If the upload fails, you get a `400` with `{ "success": false, "error": true }` (the file
could not be written) or `{ "error": "unsigned request" }` (the session was unknown,
expired or already used). In both cases go back to step 3 for a new session and upload
again. You do not need to repeat step 2.

## 5. Register the video

Until this call succeeds, the file is not in your library and nothing processes it.

```bash
curl -X POST 'https://octopus.livepush.io/streams/me/videos' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "Xk2fP9qLm",
    "Key": "nsAbC123xY_/Xk2fP9qLm.mp4",
    "zone": "zn_35hk0gxy_pr",
    "uploadUrl": "https://vod-uploads-middleware-api.livepush.io/uploads/Qe8rT2pZx",
    "label": "Morning session",
    "uploadName": "morning-session.mp4",
    "size": 734003200
  }'
```

```json
{
  "id": "Xk2fP9qLm",
  "label": "Morning session",
  "uploadName": "morning-session.mp4",
  "size": 734003200,
  "zone": "zn_35hk0gxy_pr",
  "mediaInfo": {},
  "createdAt": "2026-12-02T08:00:00.000Z"
}
```

| Field | Value |
| --- | --- |
| `id`, `Key`, `zone` | From step 2. |
| `uploadUrl` | The session URL from step 3. |
| `label` | The title shown in your library. |
| `uploadName` | The original filename. |
| `size` | The file's size in bytes. |
| `description` | Optional. Shown in your library. |
| `encoding_preset` | Optional. Omit to keep the original quality, which is the dashboard's default. |
| `mediaInfo` | Optional. The dashboard sends what the browser reads from the file: `duration` in **milliseconds**, `width` and `height`. Livepush inspects the file after registration and fills in the full details either way. |

The `id` in the response is the video id you schedule with from now on.

To put the video in a folder, use
[Move a video into a folder](/videos/move-a-video-into-a-folder/) after registering it.

## 6. Wait until it is ready

After registering, Livepush inspects the file (`inspected` turns `true` and `mediaInfo`
gains full track details), queues it for encoding (`encodeQueuedAt`), encodes it
(`encodeStartedAt`), and finally marks it encoded. Check with
[Get video by ID](/videos/get-video-by-id/):

```bash
curl -X GET 'https://octopus.livepush.io/streams/me/videos/Xk2fP9qLm' \
  -H 'Authorization: Bearer YOUR_API_TOKEN'
```

```json
{
  "id": "Xk2fP9qLm",
  "label": "Morning session",
  "encodable": true,
  "inspected": true,
  "encodeQueuedAt": "2026-12-02T08:01:40.000Z",
  "encodeStartedAt": "2026-12-02T08:02:30.000Z",
  "encoded": true,
  "encodedAt": "2026-12-02T08:21:44.000Z",
  "encoderLog": { "percent": 97.83 },
  "mediaInfo": { "duration": 3540000, "width": 1920, "height": 1080, "tracks": ["…"] }
}
```

- **The video is ready to schedule when `encoded` is `true` and `encodedAt` is set.** Poll
  every 30 to 60 seconds until both hold.
- **Do not wait on `encoderLog.percent`.** It is the last progress value reported and often
  stops below 100 on a finished video. It can also be missing
  entirely, including on videos that encoded fine.
- **Check `encodable` on the first poll.** When it is `false`, the video was not queued for
  encoding and `encoded` will never turn `true`, so stop polling rather than waiting
  forever.

## The whole flow in one script

```javascript
import { readFile, stat } from 'node:fs/promises';
import { basename } from 'node:path';

const API = 'https://octopus.livepush.io';
const UPLOADS = 'https://vod-uploads-middleware-api.livepush.io';
const auth = { Authorization: `Bearer ${process.env.LIVEPUSH_TOKEN}` };

async function call(url, init = {}) {
  const res = await fetch(url, { ...init, headers: { ...auth, ...init.headers } });
  const body = await res.json();
  if (!res.ok) throw new Error(`${res.status} ${JSON.stringify(body)}`);
  return body;
}

const json = (data) => ({
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(data),
});

export async function uploadVideo(path, label, type = 'video/mp4') {
  const { size } = await stat(path);
  const originalFilename = basename(path);

  // 1. storage zone
  const specs = await call(`${API}/streams/me/videos/storage_specs`);
  const zone = specs.defaultStorageZone ?? specs.storageZones.find((z) => z.isDefault)?.id;

  // 2. upload specification
  const target = await call(
    `${API}/streams/me/videos/uploadurl`,
    json({ originalFilename, type, size, zone }),
  );

  // 3 + 4. session, then the file (a session takes one attempt, so open a new one per try)
  const file = await readFile(path);
  let sessionUrl;
  for (let attempt = 1; ; attempt++) {
    ({ uploadUrl: sessionUrl } = await call(`${UPLOADS}/uploads/new`, json(target)));
    try {
      await call(sessionUrl, { method: 'PUT', headers: { 'Content-Type': type }, body: file });
      break;
    } catch (err) {
      if (attempt === 3) throw err;
    }
  }

  // 5. register
  return call(`${API}/streams/me/videos`, json({
    id: target.id,
    Key: target.Key,
    zone: target.zone,
    uploadUrl: sessionUrl,
    label,
    uploadName: originalFilename,
    size,
  }));
}
```

`readFile` holds the whole file in memory, which is fine for most videos. For very large
files, stream it instead (for example `fs.createReadStream(path)` passed as `body` with
`duplex: 'half'`).

## Multipart uploads

The API also has multipart upload endpoints
([Start a multipart upload](/videos/start-a-multipart-upload/) and the calls after it).
They are closed to every account unless enabled on request, which is what
`isMultipartUploadDisabled: true` in step 1 means. Use the flow above unless multipart has
been enabled for your account.

## Next steps

- Schedule the video as a broadcast: [Pre-recorded streams](/guides/pre-recorded-streams/)
- Run scheduled broadcasts end to end: [Broadcast automation](/guides/broadcast-automation/)
- Import from a URL instead of uploading a file: [Video imports](/guides/video-imports/)
