Cloudflare R2 buckets can be used to store static assets like images and GIFs for the Discourse community, but they cannot be used to store community backups!
Introduction:
Cloudflare R2 object storage can be used as an alternative to Amazon S3 for storing uploads for your Discourse forum. The following steps outline how to configure this.
Configuration Steps:
Enable S3 uploads: Check the box to enable S3 uploads in your Discourse settings.
S3 access key ID: Enter the API key ID for your R2 storage bucket. This is the ID provided when you created an API token for your bucket.
Secret access key: Enter the secret key that was provided when you created the API token granting access to your storage bucket. Important: This secret key is only displayed once, so make sure to back it up securely.
S3 region: You can enter any region, it doesn’t matter for R2.
S3 upload bucket: Enter the name of your R2 storage bucket.
S3 endpoint: Enter the S3 API link for your R2 bucket, which is in the format of https://xxxxxx.com. Refer to the Cloudflare R2 dashboard to find this link.
S3 CDN URL: Enter the public R2.dev storage bucket URL for your bucket. This will also be found in your Cloudflare R2 dashboard.
Completion:
Once these settings are configured, your Discourse forum will be set up to use Cloudflare R2 for storage.
Free Tier Information:
Cloudflare’s R2 service provides a free tier that includes 10 GB of storage, 1 million uploads, and 1 million read operations per month.
Thank you for your feedback. I have carefully read the guide previously, and I believe the advice regarding Cloudflare R2 is incorrect. The article suggests that the Discourse community does not support Cloudflare R2 buckets. However, in reality, Cloudflare R2 is highly compatible with S3 and can perfectly handle image and file uploads and downloads for the Discourse community. This has been verified through practical application on my community (starorigin.net).
It’s much better to put the S3 settings in the yml file than configure them via the UX and store them in the database. Have you tried restoring your database to a new server?
Once you’ve set things up the recommended way, you can edit that topic or make a comment and ask someone else to.
You’re right, I use a Cloudflare R2 storage bucket to store my community’s images, GIFs, and other resources. This greatly reduces the load on the community server and speeds up page loading.
I haven’t set up automatic backups for my community to be stored in the Cloudflare R2 storage bucket because Cloudflare R2 buckets do not support storing compressed files. However, Cloudflare R2 storage can store the community’s PDFs, images, GIFs, and other static resources, which is also very good.
Thank you for the reminder, I will highlight this part.
Cloudflare R2 buckets can be used to store static assets like images and GIFs for the Discourse community, but they cannot be used to store community backups!
Just to update this post I had some gotchas that needed to be included before cloudflare worked for me.
1. Region
This wasn’t true, I had to use “auto” or the region I selected, auto is easier so use auto.
if you need to know which options you can use, try with any random string in your region and:
I also confirmed the API keys are account API keys instead of just bucket-specific keys(as mentioned in the post). Also my Discourse instance shows this:
I believe all of that is correct.
Be sure the the CDN_URL (https://pub-xxx.r2.dev)
has public read access so anonymous users can see the assets.
You can tell what’s going on in the browsers dev tools. You’ll get a bunch of 403s and red requests in the network tab if the permissions are wrong.
That’s one way to do it but that’s not the recommended way, and you’ll experience issues.
Assuming you already have your domain and cloudflare is your DNS already:
inside the S3 bucket settings there’s a public access setting.
set a unique subdomain for it. (cloudflare will automatically make the DNS record for you as well as proxying and cache)
Have you gotten backups to also work to Cloudflare R2, and is it possible(assuming backups to Cloudflare R2 are possible), to make it so it backups both locally and to Cloudflare R2?
Also does the script uploading all the assets mean that it will delete them locally(to free up storage)? Or is there a separate procedure I need to do that?
Thank you for taking the time to help me with this
I personally haven’t tried.
My forum falls under the “unsupported” category because my database is external and I have a different backup strategy than the pg_dumps the forum uses.
from what I hear backups don’t work on cloudflare but nothing stopping you from trying it.