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.
What to enter before generating R2 CORS JSON
The best CORS policy starts with the real browser request, not a generic template. Before generating a Cloudflare R2 CORS config, collect the app origin, the object URL host, the upload or download method, and the request headers from DevTools. A production app at https://app.example.com and a local app at http://localhost:3000 are two different origins. If both need access, both must be present in AllowedOrigins.
For browser uploads, inspect your frontend code as well. A simple fetch(presignedUrl, { method: 'PUT', body: file }) may still send Content-Type. A richer upload component may add checksum, ACL, or metadata headers. Those headers become part of the preflight request and need to be allowed by the bucket policy.
Recommended R2 CORS policy shape
Keep the production policy narrow. Add only the origins that should use the bucket from a browser, only the methods your app actually calls, and only the headers that appear in Access-Control-Request-Headers. Wildcards can be useful while debugging, but a clean R2 policy is easier to audit when it names the real app domains.
| Scenario | Use this in the generator | Avoid |
|---|---|---|
| Production upload | Exact HTTPS app origin, PUT or POST, Content-Type, x-amz-* | A global wildcard origin |
| Local testing | Add localhost with the correct port | Assuming production origin covers localhost |
| Public image read | GET and HEAD, optional Content-Length exposure | Adding upload methods unnecessarily |
| Reading upload result | Expose ETag if JavaScript stores it | Expecting JS to see every response header |
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.
R2 CORS generator FAQ
Can I use the same CORS JSON for S3 and R2?
The rule concepts are similar, but the wrapper can differ between provider tools. Spoold shows R2-ready JSON and AWS CLI-ready JSON separately so you can copy the version that matches the place you are pasting it.
Does CORS make a private R2 object public?
No. CORS controls what the browser is allowed to read after authorization succeeds. Private objects still need a valid signed URL, token, worker, or other access path.
Why does the browser still fail after I update CORS?
Check whether the failing request is hitting the same bucket or custom domain you updated. Also retest the preflight request, because cached responses and stale deployment settings can make a fixed policy look broken for a few minutes.
Related Tools
Related Articles
How to Remove Null and Empty Fields from JSON
Clean JSON objects and API payloads by removing null values, empty strings, empty arrays, and empty objects. Learn safe cleanup rules, examples, and when not to strip fields.
How to Write Regex for Log Files
Create practical regex patterns for logs. Learn how to match timestamps, levels, request IDs, IP addresses, URLs, status codes, and error messages from text samples.
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.
Try It Now
Put this guide into practice with our free tools. No sign-up required.
Open S3/R2 CORS Tool