Cloudflare Pages & R2 Storage
Deploy full-stack apps on Cloudflare Pages with R2 (S3-compatible, zero egress fees) and D1 edge SQLite.
Why
R2 charges $0 egress (vs S3 $0.09/GB), saving 80% on image/video heavy apps. Pages Functions run on Workers runtime (300+ edge locations, 50ms cold start).
Combined: full-stack edge apps with no egress bill.
When
Choose Pages + R2 for image galleries, video hosting, file-sharing apps, and any workload where egress dominates cost. Avoid for apps needing long-running compute (use Cloud Run) or VPC-private resources.
How
Example
Common Problems
- ⚠R2 object not found — key is case-sensitive, check exact path and leading slashes
- ⚠Pages Functions 50ms CPU limit — image processing hits wall, use Image Resizing instead
- ⚠Multipart upload >100MB — R2 single PUT limit, use multipart upload API
- ⚠D1 write conflicts — single primary, concurrent writes fail, use KV for counters
Best Practices
- ✓Use R2 for all user uploads — zero egress means CDN serving is free
- ✓Cache R2 responses with Cache API — set Cache-Control, edge caches for free
- ✓Use Cloudflare Images for transforms — offloads resize/compress from your code
- ✓Git-connected Pages for auto-deploy — push to main, preview deploy per PR
FAQ
What is Cloudflare Pages & R2 Storage and what problem does it solve?
Deploy full-stack apps on Cloudflare Pages with R2 (S3-compatible, zero egress fees) and D1 edge SQLite. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.
How do I get started with Cloudflare Pages & R2 Storage in 5 minutes?
Two steps to run it: (1) Create Pages project — npx wrangler pages project create myapp; (2) Bind R2 — wrangler r2 bucket create assets, add binding in dashboard. Validate on the free tier first, then wire into production.
What is the #1 pitfall with Cloudflare Pages & R2 Storage?
The most frequent issue is: R2 object not found — key is case-sensitive, check exact path and leading slashes. Run a pre-launch checklist item by item, and add policy/config scanning in CI.
What are the best practices for Cloudflare Pages & R2 Storage?
Best practices for Cloudflare Pages & R2 Storage include: Use R2 for all user uploads — zero egress means CDN serving is free; Cache R2 responses with Cache API — set Cache-Control, edge caches for free; Use Cloudflare Images for transforms — offloads resize/compress from your code. The first one — "Use R2 for all user uploads — zero egress means CDN serving is free" — should be a team default baked into your IaC templates.
How do I control cost and avoid bill surprises with Cloudflare Pages & R2 Storage?
Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Cloudflare Pages & R2 Storage options offer a free tier — validate within free quota before scaling.