Skip to content
cloudflare-r2-bucket-management-and-access logo

Cloudflare R2 Bucket Management & Access Skill

cloudflare-r2-bucket-management-and-access

Use this skill to configure Cloudflare R2 buckets, access control, lifecycle policies, public/private assets, and integration with Hono Workers using read/write/delete/list operations and signed-access patterns.

SKILL.md

Full skill instructions

Cloudflare R2 Bucket Management & Access Skill

Purpose

You are the assistant responsible for managing R2 storage in production including:

  • Bucket provisioning & environment separation
  • Public/​private access strategy
  • Upload/​download/​stream patterns
  • Lifecycle rules & retention policies
  • Signed URL access patterns
  • Asset optimization + access performance

Use this skill when handling Cloudflare R2 + Hono Worker integration beyond basic uploads.

Do not use this skill for:

  • D1 schema or migrations → cloudflare-d1-migrations-and-production-seeding
  • Core Hono routing → hono-app-scaffold
  • Auth logic → hono-authentication

Environment-Aware Bucket Setup

This skill knows how to structure R2 per environment:

[[r2_buckets]]
binding = "BUCKET"
bucket_name = "my-bucket-dev"
preview_bucket_name = "my-bucket-dev"

[env.staging]
[[env.staging.r2_buckets]]
binding = "BUCKET"
bucket_name = "my-bucket-staging"

[env.production]
[[env.production.r2_buckets]]
binding = "BUCKET"
bucket_name = "my-bucket-prod"

Claude should:

  • Default to separate buckets per environment
  • Suggest mirroring structure between staging & prod
  • Prevent mixing prod bucket during dev

R2 Access Permission Strategy

R2 can be accessed in multiple ways — this skill helps choose between:

ModeUse Case
Private (default)User uploads, internal assets
Public ReadImages, static assets, public files
Signed-access URLsLimited-time external file sharing
Proxy download route via HonoControlled rule-based access

This skill selects approach based on context.

Best practice: Keep buckets private, expose objects through Worker/​Routes or signed URLs.


Private Access (Recommended Default)

Use Cloudflare Worker as controlled access:

app.get("/​file/:key", async (c) => {
  const key = decodeURIComponent(c.req.param("key"));

  const obj = await c.env.BUCKET.get(key);
  if (!obj) return c.notFound();

  return new Response(obj.body, {
    headers: { "Content-Type": obj.httpMetadata?.contentType ?? "application/​octet-stream" }
  });
});

This enables auth-check:

if (!c.get("user")) return c.json({ auth: false }, 401);

Public Access Mode

Enable public read with bucket policy:

wrangler r2 bucket policy put BUCKET << 'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "r2:GetObject",
      "Resource": "BUCKET/​*"
    }
  ]
}
EOF

Use only for assets intended to be publicly hosted (CDN optimized).


Upload Handling (secure)

const file = await c.req.formData().then(f => f.get("file") as File);
const key = `users/​${c.get("user")?.id}/​${Date.now()}-${file.name}`;

await c.env.BUCKET.put(key, await file.arrayBuffer(), {
  httpMetadata: { contentType: file.type }
});

return c.json({ key, url: `/​file/​${encodeURIComponent(key)}` });

The skill ensures safe naming conventions:

  • No raw user-supplied keys
  • Timestamp or UUID prefix
  • Supports multi-tenant structures

R2 Lifecycle Policies

Claude may apply retention or expiration policy suggestions:

PolicyBenefit
Auto-delete after X daysTemporary file cleanup
Move to cold storage after XCost reduction
Prevent overwrite unless flaggedAudit safety

Example JSON policy reference:

{
  "Rules": [
    {
      "ID": "auto-expire-temp",
      "Filter": { "Prefix": "temp/" },
      "Expiration": { "Days": 30 }
    }
  ]
}

Signed URL Access (download/​share)

Cloudflare does not sign natively — we generate JWT-contained key + expiry:

import { SignJWT, jwtVerify } from "jose";

export async function createSignedURL(key: string, expSec: number, secret: string) {
  const token = await new SignJWT({ key })
    .setProtectedHeader({ alg: "HS256" })
    .setExpirationTime(Math.floor(Date.now()/​1000) + expSec)
    .sign(new TextEncoder().encode(secret));

  return `/​download/​${token}`;
}

app.get("/​download/:token", async (c) => {
  const secret = c.env.JWT_SECRET;
  const { payload } = await jwtVerify(c.req.param("token"), new TextEncoder().encode(secret));
  const obj = await c.env.BUCKET.get(payload.key);
  if(!obj) return c.notFound();
  return new Response(obj.body);
});

This simulates presigned URLs safely.


Directory-like Prefixing

Claude may suggest folder-style structure for organization:

/​public/​assets/​*
/​users/[id]/​uploads/​*
/​tenants/[id]/​invoices/​*
/​tmp/​uploads/​*

Naming rules enforced by this skill:

  • Avoid exposing tenant IDs publicly unless hashed
  • PascalCase or kebab-case predictable
  • Versionable storage layout (v1/​avatars) for migrations

Listing + Search

const result = await c.env.BUCKET.list({ prefix: `users/​${id}/` });
return c.json(result.objects.map(o => ({ key: o.key, size: o.size, date: o.uploaded })));

Skill advises pagination if results exceed limits.


CI/​CD Hooks For R2 Deployments

This skill suggests combining with future CI/​CD workflow:

wrangler deploy --env production

Then apply bucket policy or migration tasks post-deploy.

For automation:

  • cache invalidation
  • namespace provisioning
  • retention checks

Example Prompts That Activate This Skill

  • “Store files in R2 with security rules.”
  • “Make public CDN bucket for static assets.”
  • “Generate signed URLs for temporary downloads.”
  • “Organize tenant bucket structure cleanly.”
  • “Set expiration policy for old file uploads.”

Interactions With Other Skills

SkillHow it connects
hono-r2-integrationThis skill expands it with policy, access control, public/​private modes
cloudflare-worker-deploymentEnsures R2 bindings are correctly mapped across envs
cloudflare-d1-migrations-and-production-seedingNot DB schema — but both require env-controlled versioning
hono-authenticationUser-based folder ownership, signed URL verification

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View