Setting up Cloudflare R2 buckets for Active Storage

07-Feb-2025 65
Rails comes with a built-in support for saving and uploading files to S3 and S3-compatible storage services in Active Storage. Here’s how to set up Cloudflare R2.To start using Cloudflare R2, select R2 Object Storage from the menu on the left navbar. If you are on free plan you’ll need to subscribe first. Then you can click + Create bucket and give your bucket a name. Choose meaningful names for your buckets. I usually append the environment to the name. Cloudflare will auto assign your bucket location based on your actual location and providing a hint might not work. Not great doing this on holidays. TIP: If you are hosting in EU, you can at least choose Specify jurisdiction and force it to be within EU. Then on the bucket page choose Settings and include the following CORS:.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle