I've been using ShareX for many years now to quickly share images and small files with friends and coworkers online. It's a fantastic tool, and while you can use it to upload to shared image hosts like Imgur, I have advocated for years to pair it with some cloud storage such as Backblaze B2, so you can continue to own and control your files, and don't have to worry about image compression or any data loss.
One of my most popular blog posts from 2019 details how to use Backblaze B2 with Cloudflare Workers for free image hosting, and uses ShareX as the example uploader for this. I've received so many nice messages over the years from users who have used that post as an introduction to both Backblaze and Cloudflare, and it continues to be a point of discussion online. 👀
Cloudflare R2 is a new object product from Cloudflare, designed to rival competing products such as Amazon's Simple Storage Service (S3). The best part about Cloudflare R2 is their commitment to the Bandwidth Alliance, and building upon this to provide absolutely zero-cost egress for stored objects!
While that sounds great, we already had free egress with Backblaze R2 and our Cloudflare setup before, so what other things can R2 provide?
- First-party Workers integration
- Automatic replication of objects to locations they're frequently requested from
- Other integrations with Cloudflare products in future
While automatic replication of objects is super cool, I don't really care about that for my personal image hosting, so the most exciting one there for me is the first-party Workers integration, which can simplify my previous setup tremendously. Storage, configuration, DNS, etc. all in once place. 🎉
First, you will want to download and install
wrangler, Cloudflare's tooling for Workers, and then authenticate using
wrangler login. You can find information about this on their docs here.
Next, let's move on to configuring and setting up our R2 bucket.
wrangler r2 bucket create <bucket name>. For the purpose of this example, I'll be using
- You can double check your bucket has been created by running
wrangler r2 bucket list.
- Clone the GitHub Repository at https://github.com/Cherry/ShareX-R2-Cloudflare-Workers and follow the installation instructions.
- All of the necessary configuration should be documented in the
README, but if you want to dig into the code, the R2 docs are a great place to start.