A cloudflare worker based REST API for your R2 bucket.
Usage:
- Change the
bucket_name
andpreview_bucket_name
inwrangler.toml
if 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 TOKEN
header, whereTOKEN
is an encrypted JWT using@proselog/jwt
andENCRYPT_SECRET
. The request content type should bemultipart/form-data
with following fields:file
:File
file 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.