All skills
theprimeagen avatar

/cloudflare-r2

@21f6c25
by theprimeagentheprimeagen/skills233 stars
6

Cloudflare R2 bucket binding usage rules

  • 1 file
  • 1.4 KB
  • Updated 7 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/theprimeagen/skills/cloudflare-r2

This session only. Nothing lands on disk.

SKILL.md

≈14 tokens always: the name and description. ≈342 when used: this file.

Cloudflare R2

Rules

  1. Declare bucket bindings in wrangler.jsonc under r2_buckets with both binding and bucket_name; keep this file as the source of truth.
  2. Access buckets via env.<BINDING> inside each Worker handler, and keep the binding name identical in both config and code.
  3. For object operations, handle get() misses (null) explicitly, set httpMetadata (for example contentType) on put(), and return clear HTTP status codes.

Example 1: wrangler.jsonc

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2026-02-24",
  "r2_buckets": [
    {
      "binding": "FILES",
      "bucket_name": "my-files"
    }
  ]
}

Example 2: Minimal put()

await env.FILES.put("hello.txt", "hello from r2", {
  httpMetadata: { contentType: "text/plain; charset=utf-8" },
});

Example 3: Minimal get()

const object = await env.FILES.get("hello.txt");
if (!object) return new Response("Not found", { status: 404 });

const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set("etag", object.httpEtag);

return new Response(object.body, { headers });

Note: if you mean "htmlEtags", the R2 field is actually httpEtag; use httpEtag for response etag headers because it is already correctly quoted.

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 21f6c25. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 7 months ago
globs
src/**/*.ts
alwaysApply
false

README badge

README badge for theprimeagen/skills/cloudflare-r2