pinme-r2

Implements secure R2 object storage routes in PinMe Cloudflare Workers.

3.7k|274|Updated Apr 13, 2025
One-click install
npx skills add https://github.com/glitternetwork/pinme --skill pinme-r2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pinme-r2
Source: https://github.com/glitternetwork/pinme/tree/main/skills/pinme-r2
Command: npx skills add https://github.com/glitternetwork/pinme --skill pinme-r2

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding file upload, download, and management to a PinMe-deployed Cloudflare Worker requires correct use of the injected R2 binding, streaming semantics, Range handling, and strict security controls. This Skill guides the AI to build those routes correctly without credentials, bucket configuration, or Wrangler edits.

Core Features & Use Cases

  • Streaming Uploads and Downloads: Pass request bodies directly to env.R2.put with size limits, content-type allowlists, and Range/conditional request support for downloads.
  • Secure Key Management: Generate opaque file IDs under server-derived owner prefixes, never accepting client-supplied object keys.
  • R2 and D1 Coordination: Store file bodies in R2 and searchable metadata in D1 with explicit pending/ready state transitions and compensation logic.
  • Use Case: A user asks to add profile image uploads to their PinMe app. The Skill produces authenticated upload, download, list, and delete routes using env.R2 with owner-scoped keys and proper HTTP semantics.

Quick Start

Use the pinme-r2 skill to add secure file upload and download routes to my PinMe Worker.

Frequently Asked Questions about pinme-r2

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I upload files to R2 in a Cloudflare Worker?

Pass request.body directly to env.R2.put with a server-generated key, after validating Content-Length and content type against an allowlist. Avoid calling arrayBuffer() or base64 conversion, which causes Worker memory amplification.

How do I access R2 in a PinMe Worker without credentials?

PinMe automatically injects an R2Bucket binding as env.R2 into every deployed Worker, scoped to the current project. Declare it in your Env interface and deploy with pinme save or pinme update-worker; never edit the generated wrangler.toml.

Should I store files in R2 or D1?

Store file bodies, images, and media in R2 addressed by key, and store searchable metadata like ownership, status, and size in D1. Never store complete files or base64 payloads in D1 rows.

Does R2 support HTTP Range requests for downloads?

Yes, pass the validated Range header to env.R2.get and return status 206 with content-range headers when object.range is present. Validate the header format first and translate unsatisfiable ranges to a 416 response.

Why is accepting object keys from clients insecure?

Client-supplied keys allow path traversal and access to other users' objects. Generate opaque UUID file IDs under a server-derived owner prefix like users/{userId}/files/, and derive the user ID only from verified identity claims.

When should I use multipart upload with R2?

Use multipart only when objects exceed the Cloudflare request-body limit or resumability is a product requirement. It requires authenticating every part operation, binding upload IDs to owners in durable state, and idempotent completion.