Skip to content

gitflarePublicPartly agent-ready50

cf-r2-drop

Drag-and-drop file sharing on Cloudflare R2: multipart uploads, expiring share links, previews, download counts, lifecycle expiry.

Serve the share page from the extensionless asset path0e4544f
Markdown22 lines1.2 KB

API

Errors: { "error": { "code", "message" } }.

Configuration: LINK_SECRET (HMAC key for share tokens; wrangler secret put LINK_SECRET, or .dev.vars locally, see .dev.vars.example). Without it a dev-only fallback is used; always set it in production.

Uploads

  • POST /api/uploads {name,size,type} -> small: {id,key,multipart:false}; size >= 10 MB: {id,key,uploadId,partSize:8388608,multipart:true}. Max 5 GB.
  • PUT /api/uploads/:id?name= single PUT (<= 100 MB) -> {key,name,size}.
  • PUT /api/uploads/:id/parts/:n?uploadId= -> {partNumber,etag}.
  • POST /api/uploads/:id/complete {uploadId,parts:[{partNumber,etag}]} -> {key,size,name}.
  • DELETE /api/uploads/:id?uploadId= aborts.

Links

  • POST /api/links {key,expiry:"1h"|"24h"|"7d",limit} -> {token,id,url,expiresAt,limit}.
  • GET /api/links/:id -> {downloads,revoked}; DELETE /api/links/:id revokes.
  • GET /api/links/:token/meta -> {name,size,type,expiresAt,limit,downloads,remaining,id}; no download is counted.
  • GET /s/:token share page; GET /d/:token[?inline] download (Range supported).

Cleanup

Objects carry customMetadata.expiresAt; a daily cron (0 3 * * *) deletes expired ones. scripts/lifecycle.json holds the R2 lifecycle rules.