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
Then create API credentials
https://dash.cloudflare.com/?to=/:account/r2/api-tokens
When creating these credentials ensure you give object read and write access to your bucket and make it specific to your bucket.
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
rclone
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
[static]
type = s3
provider = Cloudflare
access_key_id = [your access id]
secret_access_key = [your secret key[]
endpoint = https://[your account id].r2.cloudflarestorage.com
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
- Tha main thing to remember here is if your domain is hosted with cloudflare, this becomes very easy
Click on your bucket in R2 -> Settings
Click connect domain
I setup this as static.objectgraph.com
Then I can use the files as normal image sources
Like this image
https://static.objectgraph.com/uploads/2024/05/cloudflare-r2.png