I’m starting this topic as an ongoing discussion about using Cloudflare’s R2 service with Active Storage. The objective is to figure which features of Active Storage are supported, which aren’t, and help others configure their apps for use with Cloudflare.
R2 is Cloudflare’s object storage solution. It includes “full” S3 compatibility while being much cheaper. Check the announcement below for the full explanation.
- Announcement: https://blog.cloudflare.com/introducing-r2-object-storage
- Pricing: https://developers.cloudflare.com/r2/platform/pricing
- Cost Analysis vs S3: The Compelling Economics of Cloudflare R2 - Last Week in AWS Blog
- S3 Compatibility: https://developers.cloudflare.com/r2/platform/s3-compatibility/api/
- Creating R2 Tokens: https://developers.cloudflare.com/r2/platform/s3-compatibility/tokens/
- Finding your ACCOUNT_ID: https://developers.cloudflare.com/fundamentals/get-started/basic-tasks/find-account-and-zone-ids/
cloudflare: service: S3 endpoint: https://ACCOUNT_ID.r2.cloudflarestorage.com access_key_id: YOUR_KEY secret_access_key: YOUR_SECRET region: auto bucket: BUCKET_NAME
region attribute, an empty value or
us-east-1 are alias to
Active Storage Supported Features
- Display in
- Direct Upload:
- Public files: (missing ACL support for
In their annoucement, Cloudflare cited the “progressive migration” feature, to make it easier for existing apps to migration away from S3:
Migrations are designed to be dead simple. After specifying an existing storage bucket, R2 will serve requests for objects from the existing bucket, egressing the object only once before copying and serving from R2.
I’ve checked their documentation and everywhere in the R2 dashboard, but found no mention of this feature, so it’s possible it is not available yet.
In the interim, this can be implemented via workers. An explanation can be found below: