Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Cloudflare R2?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ashish7802-cloudflare-r2)
# Cloudflare R2 Storage Skill
> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18
> **Official Docs:** https://developers.cloudflare.com/r2/api/s3/api/
## Overview
Cloudflare R2 provides S3-compatible object storage with zero egress fees. Applications access R2 either via native Cloudflare Workers bindings (`env.MY_BUCKET`) or via the S3 API endpoint `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`.
## Installation
```bash
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
```
## Authentication
Create a scoped R2 API Token (Object Read & Write limited to specific buckets) in the Cloudflare dashboard to obtain `R2_ACCESS_KEY_ID` and `R2_SECRET_ACCESS_KEY`, alongside `R2_ACCOUNT_ID`. Always set `region: "auto"`.
## Core Concepts
- **Presigned URLs**: Native Workers R2 bindings (`env.BUCKET`) **cannot** generate presigned URLs directly. To issue presigned PUT/GET URLs for direct browser uploads, use `@aws-sdk/client-s3` + `@aws-sdk/s3-request-presigner` (with `nodejs_compat` in Workers) or `aws4fetch`.
- **CORS for Browser Uploads**: Direct browser `PUT` requests to presigned URLs fail unless an explicit CORS rule allowing your origin, `PUT`/`GET`, and `Content-Type` is configured on the R2 bucket.
- **Public Access**: Never expose private user buckets via `r2.dev`; use short-lived presigned GET URLs or an authenticated Worker proxy.
## Error Handling & Rate Limits
- Enforce `ContentType` and `ContentLength` / max file size checks when minting presigned PUT URLs.
- Retry transient `503 SlowDown` / `429` responses using SDK retries.
## Security Best Practices
- Scope R2 API tokens to a single bucket and minimum required permissions.
- Keep presigned URL expirations short (e.g., 60–300 seconds for uploads).
- Sanitize and generate server-controlled object keys (UUIDs/prefixes) rather than trusting client filenames.
## AI Pitfalls
- Setting `region: "us-east-1"` instead of `region: "auto"` or omitting the account-specific endpoint URL.
- Trying to call `env.MY_BUCKET.createPresignedUrl()` on a Workers binding (method does not exist).
- Sending a different `Content-Type` header from the browser than the one signed in `PutObjectCommand`, causing `SignatureDoesNotMatch`.
## Production Checklist
- [ ] Endpoint formatted as `https://<ACCOUNT_ID>.r2.cloudflarestorage.com` with `region: "auto"`
- [ ] Bucket-scoped R2 token stored in server env vars only
- [ ] Presigned URLs expire within 5 minutes and validate allowed MIME types
- [ ] Bucket CORS policy restricts origins explicitly (no wildcard `*` for credentialed flows)
## References
- [Cloudflare R2 S3 Compatibility](https://developers.cloudflare.com/r2/api/s3/api/)
- [Cloudflare R2 Presigned URLs](https://developers.cloudflare.com/r2/api/s3/presigned-urls/)
## Related skills
- [`aws-s3`](../aws-s3/SKILL.md) — alternative to
- [`cloudflare-workers`](../cloudflare-workers/SKILL.md) — integrates with
- [`cloudinary`](../cloudinary/SKILL.md) — works well with