Cloudflare R2

Integrate Cloudflare R2 object storage with Convex to store and serve files with high performance and low egress costs.

Installation

npm install @convex-dev/r2

About Cloudflare R2

A R2 component for Convex.

Benefits

Use cases

how to upload files to Cloudflare R2 from Convex

The @convex-dev/r2 component provides direct integration between Convex functions and Cloudflare R2. You can upload files from mutations or actions using the R2 client, which handles authentication and multipart uploads automatically.

Convex file storage with CDN

This component connects Convex to Cloudflare R2, giving you global file storage with automatic CDN distribution. Files stored in R2 are served through Cloudflare's edge network for faster delivery worldwide.

cheap file storage for Convex apps

Cloudflare R2 offers competitive storage pricing with zero egress fees. The @convex-dev/r2 component lets you store user uploads, images, and documents in R2 while keeping your Convex database focused on structured data.

Frequently asked questions

Does @convex-dev/r2 support file streaming?

Yes, the @convex-dev/r2 component supports streaming uploads and downloads for large files. This prevents memory issues when handling large files in your Convex functions and provides better performance for file operations.

How do I authenticate with Cloudflare R2 in Convex?

The @convex-dev/r2 component uses your Cloudflare R2 API credentials stored as Convex environment variables. You provide your account ID, access key, and secret key, and the component handles authentication automatically.

Can I use custom domains with R2 and this component?

Yes, @convex-dev/r2 supports custom domains configured in your Cloudflare R2 bucket settings. You can serve files through your own domain while still managing uploads and storage operations through the component.

What file types can I store using @convex-dev/r2?

The @convex-dev/r2 component can store any file type that Cloudflare R2 supports, including images, videos, documents, and binary files. There are no restrictions imposed by the component itself, only R2's standard limits.

Links