Skip to content

s3-cloudflare-r2

Use when working with AWS S3 or Cloudflare R2 for object storage — file uploads, presigned URLs, bucket policies, or CDN integration. Also use when choosing between S3 and R2 or implementing direct-to-storage uploads.

ModelSource
sonnetpack: storage
Full Reference

┏━ 🔧 s3-cloudflare-r2 ━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Use when working with AWS S3 or Cloudflare R2 … ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Both use the same SDK: @aws-sdk/client-s3. R2 is S3-compatible — swap the endpoint, keep the code. Node.js 20.x+ required (Node 18 dropped from SDK in January 2026).

ItemValue
Installnpm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
SDK@aws-sdk/client-s3 v3.x (modular)
S3 endpointAWS regional (auto-detected from AWS_REGION)
R2 endpointhttps://<ACCOUNT_ID>.r2.cloudflarestorage.com
R2 region value"auto" (required — not a real AWS region)
S3 key env varsAWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
R2 key env varsR2_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY
Node.js20.x+ required
I want to…File
Configure the S3 or R2 client and set up credentialsreference/setup.md
Upload, download, or check file existencereference/upload.md
Generate presigned PUT/GET URLs for direct browser uploadsreference/presigned-urls.md
List objects, delete files, or set bucket policiesreference/list-delete.md
Upload large files (100MB+) with multipart and parallel partsreference/multipart.md
Configure CORS, set up CloudFront or R2 custom domain, or compare S3 vs R2reference/cors.md

Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.