A Cloudflare Worker for secure, time-limited file sharing via R2 object storage.
- Configurable link expiry
- In-browser video/audio playback
- In-browser image preview
- File download
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.jsGenerates a time-limited URL to share with recipients. Default expiry is 7 days — 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
{ "r2_buckets": [{ "binding": "MY_BUCKET", "bucket_name": "your-bucket-name" }], }