r2-api
r2-api copied to clipboard
A cloudflare worker based REST API for your R2 bucket.
A cloudflare worker based REST API for your R2 bucket.
Usage:
- Change the
bucket_nameandpreview_bucket_nameinwrangler.tomlif you want. - Set
ENCRYPT_SECRET(>= 32 chars) in the worker secrets using Wrangler CLI. (for production only)
Endpoints:
- GET
/:key: Public access - POST
/: Requireauthorization: Bearer TOKENheader, whereTOKENis an encrypted JWT using@proselog/jwtandENCRYPT_SECRET. The request content type should bemultipart/form-datawith following fields:file:Filefile to upload
The object key is generated from $prefix/ + uuid() + file.extension
To generate a token using @proselog/jwt:
import { getDerivedKey, encrypt } from "@proselog/jwt"
const key = await getDerivedKey("ENCRYPT_SECRET")
const token = await encrypt({ prefix: "dev/" }, key, { expiresIn: "1h" })
For development for you can node gen-token.mjs and use the output to upload files.