agentleFS
Ghost7802Ghost7802/awesome-api-skills/skills/cloudflare-r2/SKILL.md

cloudflare-r2

Skill13 starsChanged 27 days agoMITView on GitHub

Verification Tier: code_example_tested | Last Verified: 2026-11-18 Official Docs: https://developers.cloudflare.com/r2/api/s3/api/

  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create a scoped R2 API Token (Object Read & Write limited to specific buckets) in the Cloudflare dashboard to obtain R2_ACCESS_KEY_ID and …

    line 15
  2. Very specific:

    Public Access: Never expose private user buckets via r2.dev.

    line 20
  3. Distinctive:

    Keep presigned URL expirations short (e.g., 60–300 seconds for uploads).

    line 28

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

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

Related skills

  • aws-s3 — alternative to
  • cloudflare-workers — integrates with
  • cloudinary — works well with

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.