Video Piper APIv1 Home OpenAPI spec

Docs › Uploads from a browser

Uploads from a browser

To let your users upload from your web app without exposing your key, split the work between your backend and the browser:

  1. The browser tells your backend the file name and size.
  2. Your backend calls POST /videos and POST /videos/{id}/parts, and returns only the videoId, the partSize and the part URLs.
  3. The browser PUTs each slice (file.slice(start, start + sizeBytes)) straight to its URL. Storage accepts cross-origin PUTs, and exposes the ETag header.
  4. The browser tells your backend it's done; your backend calls complete.

Part URLs expire after 15 minutes, so for a large file have the browser ask your backend for them a few at a time as it uploads, rather than all at once.

// Browser: upload the slices your backend signed
for (const part of parts) {
  const start = (part.partNumber - 1) * partSize;
  const response = await fetch(part.url, { method: "PUT", body: file.slice(start, start + part.sizeBytes) });
  if (!response.ok) throw new Error(`Part ${part.partNumber} failed`);
}

For playback in the browser, pass the status's playbackUrl or streamUrl to the page (see Build your own player); for downloads, the downloadUrl, which is valid for 15 minutes.

Warm-up for faster processing

Your first parts request starts the processing container, which boots while the file uploads and then waits; it processes nothing until you complete the upload, and stands down if the upload stalls for 20 minutes, is aborted or cancelled. This takes the container start (about 30 seconds) off the end of every upload.

This happens automatically; request part URLs as you upload, since each request tells the waiting container the upload is still moving. For a video of 10 minutes or more the API also starts GPU machines near the end of the upload. If you know the file's length, send it as durationSeconds when you create the video (a hint only: it decides whether to start GPU machines early and is never used for billing or processing). For recordings, add elapsedSeconds to parts requests.