A Cloudflare Worker for secure, time-limited file sharing via R2 object storage.
- 🔒 Token-based access with HMAC-SHA256 signing
- ⏱ Configurable link expiry
- 📁 Folder structure support
- ▶ In-browser video and audio playback with range request support
- 🖼 Image preview
- ⬇ File download
- 📄 Supports files of any size via chunked streaming
git clone https://github.com/itoschum/r2-share-worker.git
cd r2-share-worker
npm installEdit wrangler.jsonc and set your R2 bucket name:
Generate a secret:
openssl rand -hex 32Set it in Cloudflare:
wrangler secret put SECRET_KEYFor local development, create .dev.vars:
SECRET_KEY=your-secret-here
WORKER_URL=https://your-worker.workers.dev
rclone copy ./your-folder your-r2-remote:your-bucket --progresswrangler deploynode scripts/generate-sharing-link.jsOutputs a time-limited URL to share with recipients. Default expiry is 24 hours — edit the script to change this.
├── src/
│ └── worker.ts # Cloudflare Worker
├── scripts/
│ └── generate-sharing-link.js # Share link generator
├── .dev.vars # Local secrets (never commit)
├── wrangler.jsonc # Cloudflare Worker config
└── package.json
- Links expire after a configurable time period
- HMAC-SHA256 tokens prevent link forgery
- R2 bucket is private — all access goes through the Worker
- Rotating
SECRET_KEYimmediately invalidates all existing links
Pushes to master automatically deploy via Cloudflare's GitHub integration.
{ "r2_buckets": [{ "binding": "MY_BUCKET", "bucket_name": "your-bucket-name" }], }