secondsky/claude-skills / plugins/cloudflare-r2/skills/cloudflare-r2
cloudflare-r2
VerifiedCloudflare R2 S3-compatible object storage. Use for buckets, uploads, CORS, presigned URLs, or encountering R2_ERROR, CORS failures, multipart issues.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 13.8 KB |
| references/advanced-features.md | markdown | 14.4 KB |
| references/cloudflare-access-integration.md | markdown | 14.5 KB |
| references/common-patterns.md | markdown | 12.8 KB |
| references/cors-configuration.md | markdown | 2.7 KB |
| references/data-catalog-iceberg.md | markdown | 15.1 KB |
| references/event-notifications.md | markdown | 15.8 KB |
| references/performance-optimization.md | markdown | 15.8 KB |
| references/r2-sql-integration.md | markdown | 14.5 KB |
| references/s3-compatibility.md | markdown | 7.7 KB |
| references/setup-guide.md | markdown | 8.5 KB |
| references/workers-api.md | markdown | 9.7 KB |
| templates/r2-cors-config.json | config | 3.3 KB |
| templates/r2-multipart-upload.ts | script | 5.7 KB |
| templates/r2-presigned-urls.ts | script | 7.2 KB |
| templates/r2-simple-upload.ts | script | 5.1 KB |
| templates/wrangler-r2-config.jsonc | other | 1.1 KB |
references/cors-configuration.md
View on GitHub# R2 CORS Configuration Guide
**Last Updated**: 2025-11-26
**Official Docs**: https://developers.cloudflare.com/r2/buckets/cors/
---
## Dashboard Configuration
1. Cloudflare Dashboard → R2 → Your bucket
2. Settings tab → CORS Policy → Add CORS policy
---
## Common Scenarios
### Public Assets (Read-Only)
```json
{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["Range"],
"MaxAgeSeconds": 3600
}
]
}
```
**Use when**: Serving public images, videos, or static assets from R2.
### Upload/Download (Full Access)
```json
{
"CORSRules": [
{
"AllowedOrigins": ["https://app.example.com"],
"AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedHeaders": ["Content-Type", "Content-MD5"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3600
}
]
}
```
**Use when**: Allowing browser uploads and downloads from specific domain.
### Development Environment
```json
{
"CORSRules": [
{
"AllowedOrigins": ["http://localhost:3000", "http://localhost:5173"],
"AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedHeaders": ["*"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3600
}
]
}
```
**Use when**: Local development and testing.
---
## Troubleshooting CORS Errors
### Error: "CORS policy: No 'Access-Control-Allow-Origin' header"
**Cause**: CORS not configured or origin not allowed.
**Solution**:
1. Add origin to `AllowedOrigins` in bucket CORS policy
2. Verify method is in `AllowedMethods`
3. For `*` origin, ensure credentials mode is not 'include'
### Error: "CORS policy: Request header field X is not allowed"
**Cause**: Custom header not in `AllowedHeaders`.
**Solution**: Add header to `AllowedHeaders` or use `["*"]` for development.
### Error: Presigned URLs failing with CORS
**Cause**: Presigned URLs bypass worker CORS headers.
**Solution**: Configure CORS at bucket level (Dashboard), not in Worker.
---
## Security Best Practices
1. **Never use `["*"]` origin in production** - Always specify exact domains
2. **Limit methods** - Only allow methods your app actually uses
3. **Set reasonable MaxAgeSeconds** - 3600 (1 hour) is typically sufficient
4. **Use ExposeHeaders** - Include ETag for caching validation
5. **Consider preflight caching** - Higher MaxAgeSeconds reduces preflight requests
---
## Testing CORS Configuration
```bash
# Test GET request
curl -H "Origin: https://example.com" \
-H "Access-Control-Request-Method: GET" \
-X OPTIONS \
https://bucket.account.r2.cloudflarestorage.com/file.txt
# Should return Access-Control-Allow-Origin header
```
See `templates/r2-cors-config.json` for more examples.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |