It took me forever to figure out how to do all of this, so I wanted to make this guide to make it easier for people. Serving your images this way is supposed to make your website load faster. My Discourse setup combines a DigitalOcean droplet, BackBlaze B2 S3, BunnyCDN, and the free version of Cloudflare.
I went with these services after doing a bit of research into reliability, pricing, and benchmarks. They looked like the best options for me. Cloudflare helps with security, but will also slow the site down slightly from what I understand so you should look into that. Cloudflare and Backblaze have a partnership that is supposed to allow for free data transfer.
Although Cloudflare is called a CDN, it doesn’t work like regular CDN’s and I’m not sure it will work alone for setting up S3 with Discourse. You will possibly need another CDN provider, BunnyCDN works well for me. If someone has successfully done it with just Cloudflare, let me know how
How to set uploads to S3:
First, you need to sign up at Backblaze, then make buckets, and insert the details into the Discourse settings:
Then you sign up with BunnyCDN and follow this guide:
https://bunnycdn.com/?ref=qcp86164sq (referral link, I get a 20$ credit on my bill)
After you create your BunnyCDN pull zone, you need to get the correct url to insert into your Discourse admin backend setting for “s3 cdn url”. Go to your bunnycdn dashboard>pull zones>manage pull zones>click your zone> copy the url next to “host name”
Save the changes in Discourse admin setting area.
Press ctrl+f5 twice in your browser on your discourse site.
Do a test by uploading an image in the discourse text composer. Inspect the test image element, or view the images source to make sure it worked. The url should look different than your normal domain, it should be something like example.b-cdn.net / filename
Now, every time someone uploads an image, it will be in your backblaze bucket and not taking up room on your digitalocean droplet
Backup Uploads to S3
If you want to setup your Discourse backups to go into your backblaze bucket, you need to do this:
In the guide I posted higher in this thread, pay attention to how he explains you need two separate buckets. One bucket is public, this is your uploads bucket for your users to upload images on your forum. The other bucket is private, this is your backup’s bucket. It’s important to make automated backups of Discourse just in case anything breaks, then you can load your backup and fix it.
On your BunnyCDN dashboard, you should create a second pull zone. Your first pull zone was for uploads, this new pull zone will be for backups.
bunnycdn dashboard>pull zones>add pull zone
Follow the same guide I linked to earlier, BunnyCDN’s “How to Speed up your Backblaze B2 file delivery with BunnyCDN” but this time you would link the new pull zone to your backup bucket instead of your uploads bucket.
I recommend using the “high volume tier 5$/TB” on BunnyCDN’s pull zone creation page, I think backups don’t need the more expensive/faster tier “standard tier 10$/TB” that I used my for uploads bucket.
Set your backup settings in the discourse admin settings area. “backup location” should be set to S3 and “s3 endpoint” should point to what you have at backblaze, something like this:
CTRL+F5 twice on your website to clear cache
Start a backup, let it finish. Then wait 5 minutes and check your backblaze backups folder, you should see the new backup there.
Migrating Older Images:
This step is optional but recommended, especially if your low on storage on your server. So you got everything set up for new image uploads, but older images can be transfered to your buckets as well. To make this process work, you need to follow this:
Domain name stuff:
This last step is optional, but you need to set this up to make the data transfer free between cloudflare and backblaze. Keep in mind that backblaze data has to hit cloudflare FIRST for it to be free transfer fee. After you follow this guide, change your BunnyCDN origin url to look something like this “https://images.yourwebsite.com/file/uploads”