This site is not affiliated with or endorsed by Cloudflare, Inc. It simply showcases experiments built using Cloudflare services.
Cloudflare Experiments

Stream Video Demo

Create Stream direct upload URLs and signed playback tokens

Create Cloudflare Stream direct upload URLs and signed playback tokens from a Worker via the Stream binding. Locally (or without a live binding) endpoints return demo values with mode: "demo".

Features

  • Direct creator upload URL via env.STREAM.createDirectUpload
  • Signed playback token via env.STREAM.video(uid).generateToken
  • Demo mode when the Stream binding is unavailable

API Reference

POST /upload-url

Create a one-time direct upload URL.

Body (optional JSON)

FieldRequiredDescription
maxDurationSecondsNoMax video length in seconds (1–21600, default 3600)

Example Request

curl -X POST "https://your-worker.workers.dev/upload-url" \
  -H "Content-Type: application/json" \
  -d '{"maxDurationSeconds": 600}'

Success Response

{
  "uploadURL": "https://upload.cloudflarestream.com/...",
  "uid": "video-uid",
  "mode": "live",
  "maxDurationSeconds": 600
}

Error Codes

  • 400 - Invalid JSON / duration (INVALID_BODY)
  • 502 - Stream API failure (STREAM_ERROR)

GET /playback-token

Generate a signed playback token for a video UID.

uid string (required)

Stream video UID.

Example Request

curl "https://your-worker.workers.dev/playback-token?uid=VIDEO_UID"

Success Response

{
  "token": "signed-playback-token",
  "uid": "VIDEO_UID",
  "playbackUrl": "https://videodelivery.net/signed-playback-token/manifest/video.m3u8",
  "mode": "live"
}

Error Codes

  • 400 - Missing uid (INVALID_UID)
  • 502 - Stream API failure (STREAM_ERROR)

Use Cases

  • Let end users upload video without exposing Stream API tokens
  • Issue short-lived playback tokens for private videos
  • Prototype creator-upload + secure viewing flows on Workers

Limitations

  • Requires Stream enabled on the account for live mode
  • Basic POST uploads are limited to ~200 MB (use tus via REST for larger files)
  • Demo mode returns placeholder URLs/tokens

Deployment

Click the deploy button

Deploy to Cloudflare Workers

Enable Stream

Ensure Stream is available on your Cloudflare account. The Worker binds STREAM via wrangler.json.

Test your deployment

curl -X POST "https://your-worker.workers.dev/upload-url"

Local Development

cd apps/experiments/stream-video-demo
npm install
npm run dev

Without a live Stream binding, responses include "mode": "demo".

Configuration

wrangler.json declares:

  • Stream binding STREAM

Cloudflare Features Used

On this page