Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/r2/README.md
1# Cloudflare R2 Object Storage23S3-compatible object storage with zero egress fees, optimized for large file storage and delivery.45## Overview67R2 provides:8- S3-compatible API (Workers API + S3 REST)9- Zero egress fees globally10- Strong consistency for writes/deletes11- Storage classes (Standard/Infrequent Access)12- SSE-C encryption support1314**Use cases:** Media storage, backups, static assets, user uploads, data lakes1516## Quick Start1718```bash19wrangler r2 bucket create my-bucket --location=enam20wrangler r2 object put my-bucket/file.txt --file=./local.txt21```2223```typescript24// Upload25await env.MY_BUCKET.put(key, data, {26httpMetadata: { contentType: 'image/jpeg' }27});2829// Download30const object = await env.MY_BUCKET.get(key);31if (object) return new Response(object.body);32```3334## Core Operations3536| Method | Purpose | Returns |37|--------|---------|---------|38| `put(key, value, options?)` | Upload object | `R2Object \| null` |39| `get(key, options?)` | Download object | `R2ObjectBody \| R2Object \| null` |40| `head(key)` | Get metadata only | `R2Object \| null` |41| `delete(keys)` | Delete object(s) | `Promise<void>` |42| `list(options?)` | List objects | `R2Objects` |4344## Storage Classes4546- **Standard**: Frequent access, low latency reads47- **InfrequentAccess**: 30-day minimum storage, retrieval fees, lower storage cost4849## Event Notifications5051R2 integrates with Cloudflare Queues for reactive workflows:5253```typescript54// wrangler.jsonc55{56"event_notifications": [{57"queue": "r2-notifications",58"actions": ["PutObject", "DeleteObject"]59}]60}6162// Consumer63async queue(batch: MessageBatch, env: Env) {64for (const message of batch.messages) {65const event = message.body; // { action, bucket, object, timestamps }66if (event.action === 'PutObject') {67// Process upload: thumbnail generation, virus scan, etc.68}69}70}71```7273## Reading Order7475**First-time users:** README → configuration.md → api.md → patterns.md76**Specific tasks:**77- Setup: configuration.md78- Client uploads: patterns.md (presigned URLs)79- Public static site: patterns.md (public access + custom domain)80- Processing uploads: README (event notifications) + queues reference81- Debugging: gotchas.md8283## In This Reference8485- [configuration.md](./configuration.md) - Bindings, S3 SDK, CORS, lifecycles, token scopes86- [api.md](./api.md) - Workers API, multipart, conditional requests, presigned URLs87- [patterns.md](./patterns.md) - Streaming, caching, client uploads, public buckets88- [gotchas.md](./gotchas.md) - List truncation, etag format, stream length, S3 SDK region8990## See Also9192- [workers](../workers/) - Worker runtime and fetch handlers93- [kv](../kv/) - Metadata storage for R2 objects94- [d1](../d1/) - Store R2 URLs in relational database95- [queues](../queues/) - Process R2 uploads asynchronously96