Cloudflare R2 CORS Generator: Create Bucket CORS JSON for Browser Apps
Generate Cloudflare R2 CORS JSON for public reads, browser uploads, signed downloads, and presigned URL workflows. Learn AllowedOrigins, AllowedMethods, AllowedHeaders, ExposeHeaders, MaxAgeSeconds, and Wrangler-ready config.
Generate Cloudflare R2 CORS config without guessing field names
Spoold's S3/R2 CORS Generator & Debugger creates Cloudflare R2 bucket CORS JSON for browser apps. Pick a preset, enter your app origin, choose methods such as GET or PUT, and copy dashboard-ready JSON plus a Wrangler file for applying the policy from the command line.
What is a Cloudflare R2 CORS generator?
A Cloudflare R2 CORS generator helps you create the bucket policy that tells browsers which frontend origins can read or upload objects from R2. CORS is only enforced by the browser. Your presigned URL or public object may work in curl, but the same request can fail in a web app if R2 does not return the right Access-Control-* headers.
R2 CORS fields explained
| Field | Purpose | Typical value |
|---|---|---|
| AllowedOrigins | Frontend origins allowed to access R2 from a browser. | https://app.example.com |
| AllowedMethods | Methods the browser can use after preflight succeeds. | GET, HEAD, PUT |
| AllowedHeaders | Request headers your frontend may send. | Content-Type, x-amz-* |
| ExposeHeaders | Response headers JavaScript can read. | ETag, Content-Length |
| MaxAgeSeconds | How long the browser can cache preflight success. | 3600 |
Dashboard JSON vs Wrangler JSON
R2 developers often run into a small mismatch: the dashboard-style rule list and the Wrangler file shape are not always pasted in the same wrapper. The Spoold tool shows both forms. Use the editable CORS JSON for dashboard-style policy review, and use the generated Wrangler file when running wrangler r2 bucket cors set.
Dashboard-style rule list
[
{
"AllowedOrigins": ["https://app.example.com"],
"AllowedMethods": ["GET", "PUT", "HEAD"],
"AllowedHeaders": ["Content-Type"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3600
}
]Wrangler file shape
{
"rules": [
{
"allowed": {
"origins": ["https://app.example.com"],
"methods": ["GET", "PUT", "HEAD"],
"headers": ["Content-Type"]
},
"exposeHeaders": ["ETag"],
"maxAgeSeconds": 3600
}
]
}Best presets for common R2 use cases
- Public assets: use
GETandHEAD. AddContent-Lengthto exposed headers if the frontend reads file size. - Presigned upload: use
PUT,POST, andHEAD. IncludeContent-Typeand anyx-amz-*headers your upload sends. - Signed download: use
GETandHEAD. ExposeETagonly if the frontend reads it.
How to generate R2 CORS config
- Open the S3/R2 CORS tool and choose Cloudflare R2.
- Pick a preset: public read, presigned upload, signed download, or fonts/assets.
- Enter your production origin and any localhost origin used in development.
- Add request headers from your frontend upload code.
- Copy the editable JSON or download the Wrangler file.
- Use the Debug tab if the browser still reports a preflight or missing-origin error.
Why use the debugger after generating config?
The generator gives you a good starting policy. The debugger checks the exact failing request. Paste your current R2 CORS JSON, the request origin, method, request headers, and browser console error. It will tell you whether the origin, method, headers, or exposed response headers are missing.
Related Tools
Related Articles
CSV Operations Query Tool Online: Filter, Dedupe, Compare CSV and Excel
Use Spoold's free CSV Operations tool to query CSV, TSV, and Excel .xlsx files online. Filter rows, select columns, find unique values and duplicates, dedupe CSV data, compare columns, count by category, sort rows, and run numeric summaries in your browser.
R2 Presigned URL CORS: Fix Browser Upload and Download Errors
Cloudflare R2 presigned URLs still need bucket CORS when used from a browser. Learn how to allow PUT, POST, GET, Content-Type, x-amz-* headers, ETag exposure, localhost origins, and preflight requests.
S3 CORS Policy Generator: Create AWS Bucket CORS JSON for Browser Uploads
Generate AWS S3 CORS policies for browser uploads, public reads, signed downloads, and presigned URLs. Learn CORSRules, AllowedOrigins, AllowedMethods, AllowedHeaders, ExposeHeaders, MaxAgeSeconds, and put-bucket-cors.
Try It Now
Put this guide into practice with our free tools. No sign-up required.
Open S3/R2 CORS Tool