Cloudflare R2 for Static storage

R2 is a good option if you dont want any egress fees and good for your static content. Its compatible with S3 protocol, so you can use any tools to upload your content

Signup for R2

You will have to enable for R2 in your cloudflare account via the dashboard.

Go to R2 in the left menu and create a bucket

I created a bucket called ogblog

Create a bucket

Then create API credentials

When creating these credentials ensure you give object read and write access to your bucket and make it specific to your bucket.

Credentials Screenshot

Get your account id

On the R2 - overview page, you will see your account id on the right

Once you have credentials and your account id, you can use rclone to upload your static assets


Install rclone using brew

brew install rclone

Then figure out where the config file is

rclone config file

if this file is brand new, create it and add the following entry

type = s3
provider = Cloudflare
access_key_id = [your access id]
secret_access_key = [your secret key[]
endpoint = https://[your account id]
acl = private

Now you can query your bucket using the following command, remember our entry in rclone is called static and our R2 bucket is called ogblog, so your query would be like below

rclone tree static:ogblog

Upload your contents

rclone copy -P -vv ./uploads static:ogblog/uploads

Setup public access

Click on your bucket in R2 -> Settings

Click connect domain

custom domain image

I setup this as

Then I can use the files as normal image sources

Like this image

By: Gavi Narra on: