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.
About R2:
R2 is Cloudflare’s object storage solution. It includes “full” S3 compatibility while being much cheaper. Check the announcement below for the full explanation.
For the region attribute, an empty value or us-east-1 are alias to auto.
Active Storage Supported Features
Attach:
Download:
Display in img tag:
Direct Upload:
Public files: (missing ACL support for PutObject operation)
Progressive Migration
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:
Hello,
This is very good information.
Direct uploads are not working, at least for me. There is a problem with CORS. I think they cannot be defined in Cloudflare yet.
Do you know any way to fix this? For example, action text uploads will not work.
Thanks!
You don’t need CORS support for direct upload. Just add direct: true to your file upload, and active storage will transparently upload through a signed url. Though it does get a bit more complicated if you are integrating active storage with a frontend library.
They have a solution to that that is beta now; where they only move files that are requested by your users in real time. In that way you’ll only pay what you would have paid. I guess eventually you’d need to move them all, but you can delay that expense for another time