Intro
Previously, my image hosting relied on two generous benefactors, Cloudflare and Telegraph. I thought they would outlive my blog, so I assumed this was a long-term solution — reliable, easy to use, and, most importantly, free.
But recently Telegram's CEO was arrested, and South Korea has also clashed with Telegram over censorship. Perhaps as a result, Telegraph's image hosting service can no longer upload new images. Old images are still accessible, but there's no telling when they'll disappear for good.
So I started looking for a new image hosting solution. What I wanted was reliable, easy to use, and preferably free. Cloudflare R2 + PicGo + WebP Cloud is exactly that.
This post is mainly based on this article, and also covers custom domains on WebP Cloud and migrating images from Telegraph to R2.
Deployment
As of September 2024, I can guarantee that this deployment method works.
What you need
- A Cloudflare account with a credit card linked (required to enable R2)
- A domain (not required, but cooler if you have one)
Now let's get started...
Enable Cloudflare R2
- Open the Cloudflare dashboard, select
R2, and you'll see the free tier. Click to agree and enable it. - Create a new bucket (
Create bucket)- Enter a name you like, e.g.
image. - Select a region you prefer, e.g.
APAC. - Click
Create bucketto create it.
- Enter a name you like, e.g.
- Click the
imagebucket you just created.- If you have a domain, go to
Settingsand set upCustom Domains(if your domain is already on Cloudflare, you can add it right away). - If you don't have a domain, go to
Settings, clickAllow Accessnext toR2.dev subdomain, typeallow, and you'll get an address likexxxxxx.r2.dev. - You should now be able to upload images. You can test by uploading one in the
Objectssection of theimagebucket.
- If you have a domain, go to
- Now click
R2in the left sidebar to return toOverview. UnderAccount details, clickManage R2 API TokensbelowAccount ID.- Click
Create API tokento create a new API token. - Give it a name, e.g.
image-R2. - For
Permission, selectObject Read & Write. - Under
Specify buckets, select theimagebucket you just created. - Click
Create API Tokento create it. - You'll get the info PicGo needs, including
Access Key ID,Secret Access Key, andendpoints. It's only shown once, so save it now.
- Click
- With that, you're done with the Cloudflare dashboard.
Set up PicGo
- Download PicGo.
- After installing, open the plugin settings, search for
s3, find the plugin byWayJam So, and install it. - Go to the image host settings, find
Amazon S3, and add a new config or modify the default one.- The config name is up to you, e.g.
r2. Access Key ID: enter yourAccess Key ID.Access Key Secret: enter yourSecret Access Key.Bucket: enter the bucket name you set, hereimage.Custom endpoint: enter theendpointsvalue.Custom domain: enter theCustom Domainsyou set, or thexxxxxx.r2.devaddress Cloudflare assigned to you.- Click OK.
- The config name is up to you, e.g.
- At this point, you should be able to upload images with
PicGo.
Proxy your URL with WebP Cloud
- Go to the WebP Cloud Dashboard and log in.
- In the
Pricesection on the left, you'll see the free tier. - Go to the
Homesection on the left, scroll down, and clickCreate Proxy.- Choose a region you like — I chose
Hillsboro, OR. - For
Proxy Name, enter anything, e.g.R2-image. - In
Proxy Origin URL, enter theCustom Domainsyou set, or thexxxxxx.r2.devaddress Cloudflare assigned to you. - Click
Createto create it. - You'll then be assigned an address like
xxxxxx.webp.li.
- Choose a region you like — I chose
- If you want a custom domain, open the proxy you just created and click
Custom domain. Add the corresponding entry to your DNS records as prompted; after a short wait, you can activate your custom domain inCustom domain. - Next, change the
Custom domaininPicGoto the custom domain you set inWebP Cloud, or thexxxxxx.webp.liaddressWebP Cloudassigned to you.
Migration
I have a ton of images still sitting on Telegraph's image host, and I want to move them all to R2. PicGo's pic-migrater plugin is a good choice — it's developed by Molunerfinn.
- After downloading the plugin, open the plugin settings, click the gear icon at the bottom right of the plugin, and choose
Configure plugin - picgo-plugin-pic-migrater. - Enter anything for the new file name suffix, e.g.
_new. - I set
Write old content to new filetono, so converted files are namedsource_filename_new.md, which makes them easy to review.
For some markdown files, however, pic-migrater fails to migrate them, and I haven't figured out how to fix it yet. My approach is to manually handle the files it leaves behind, one by one.
Outro
That's it.