Storage
Sample code Cloudflare Worker to make your R2 bucket accessible from public.
Minimum Requirements
- Cloudflare Account
wrangler >= 2.0.2
Note: Ensure you are using at the minimum specified version of wrangler.
Setup
- Install dependencies (including Wrangler 2)
npm install
- Create a bucket to be made public
wrangler r2 bucket create {{BUCKET_NAME}}
- Update the
wrangler.toml
to bind the R2 bucket
[[r2_buckets]]
binding = 'PUBLIC' # <= make sure this var is valid JavaScript variable name
bucket_name = 'public'
- Deploy the worker!
wrangler publish src/index.ts --name {{WORKER_NAME}}
- Done
🎉
Give it a try: https://cdn.muhfajar.id/assets/glitch/v1/img/glitch.jpg