DEV Community

Alex Spinov
Alex Spinov

Posted on

Cloudflare R2 Has a Free API You Should Know About

Cloudflare R2 is S3-compatible object storage with zero egress fees. Store and serve files globally without paying for bandwidth — a game-changer for media-heavy applications.

Why R2 Saves Thousands on Storage

A video platform was paying $3,000/month in AWS S3 egress fees. Same storage on R2: $0 egress. They saved $36,000/year by switching one line in their S3 SDK config.

Key Features:

  • Zero Egress Fees — No bandwidth charges ever
  • S3 Compatible — Use existing S3 SDKs and tools
  • Global Distribution — Automatic edge caching
  • Free Tier — 10GB storage, 10M reads/month, 1M writes/month
  • Workers Integration — Access from Cloudflare Workers

Quick Start (S3 SDK)

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3"

const s3 = new S3Client({
  region: "auto",
  endpoint: "https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com",
  credentials: {
    accessKeyId: "YOUR_ACCESS_KEY",
    secretAccessKey: "YOUR_SECRET_KEY"
  }
})

await s3.send(new PutObjectCommand({
  Bucket: "my-bucket",
  Key: "image.png",
  Body: fileBuffer
}))
Enter fullscreen mode Exit fullscreen mode

From Workers

export default {
  async fetch(request, env) {
    const object = await env.MY_BUCKET.get("image.png")
    return new Response(object.body, {
      headers: { "Content-Type": "image/png" }
    })
  }
}
Enter fullscreen mode Exit fullscreen mode

Why Choose R2

  1. Zero egress — never pay for bandwidth
  2. S3 compatible — migrate in minutes
  3. Generous free tier — 10GB free

Check out R2 docs to get started.


Need storage solutions? Check out my Apify actors or email spinov001@gmail.com for custom solutions.

Top comments (0)