Temporary file-sharing app with password protection and link expiration
Backend: Cloudflare Workers (Hono) + R2 (file storage) + KV (metadata)
Frontend: Next.js
Features:
- Temporary files with TTL and optional max-downloads
- Optional password-protected downloads
- One-time download support
Repository layout
- backend — Cloudflare Worker,
wrangler.toml,src/index.ts - frontend — Next.js app,
src/andsrc/lib/api.ts
- Node.js (18+)
- Cloudflare account with R2 bucket and KV namespace
- Wrangler CLI (
npm i -D wrangler@4recommended)
- Create an R2 bucket (via Cloudflare dashboard) — example name:
tempcloud-files. - Create a KV namespace and note the
idand (optionally)preview_id. - Edit
[bindings]in backend/wrangler.toml to set the R2 binding and KV namespace IDs. - Set
BASE_URLin backend/wrangler.toml to the worker domain you will publish (or leave ashttp://localhost:8787for local dev). - Publish the worker:
cd backend
npx wrangler deployAfter deploy you will get a https://<name>.<your-subdomain>.workers.dev URL.
- In
frontend/.env.localset:
NEXT_PUBLIC_API_URL=https://<your-worker>.workers.dev
- Install and run locally:
cd frontend
npm install
npm run dev- Build for production:
npm run build
npm run start- Frontend calls
POST /api/v1/upload/initto create a file record and get an upload URL. - The Worker proxies the upload (PUT) into R2.
- After upload the frontend calls
POST /api/v1/upload/finalizeto mark the file active.
Example upload-init (JSON) request: POST to /api/v1/upload/init with filename/size/mime.
Download URL format (frontend uses):
https://<worker>/d/<uuid> — this redirects to the worker download endpoint and handles password checks.
- CORS: Worker sets CORS headers; if you host frontend on another domain update
CORS_ORIGINinwrangler.toml. - Limits:
MAX_FILE_SIZEinwrangler.tomlcontrols max upload size. - Cleanup: the worker sets TTLs (KV
expiration) for automatic cleanup of metadata.
- If upload PUTs point to
http://localhost:8787, setBASE_URLin backend/wrangler.toml to the deployed worker domain and redeploy. - If CORS errors occur, ensure
CORS_ORIGINallows your frontend origin and redeploy the worker.
- Backend routes and logic: backend/src/index.ts
- Types and env bindings: backend/src/types.ts
- Frontend API client: frontend/src/lib/api.ts
- Frontend pages: frontend/src/app/page.tsx and frontend/src/app/d/[uuid]/page.tsx