↓ Skip to main content
  1. Posts/

Self-Hosted Image Hosting with Cloudflare R2 (Free, S3-Compatible, Globally Fast)

·254 words·1 min· loading · loading · ·
HJP
Author
HJP
Always learning, always growing.
Table of Contents

Full Chinese version: 自建 Cloudflare R2 图床:免费、S3 兼容、全球加速

The core idea
#

Writing articles means adding images, and images need a host. Cloudflare R2 is the most hassle-free option I have used: 10GB free storage + millions of reads/writes per month, S3-compatible, custom domain, and global CDN caching.

Why R2
#

  • Cheap: free tier covers personal usage;
  • Compatible: standard S3 API works with PicGo, rclone, etc.;
  • Stable: Cloudflare edge network + Cache Rules for fast loading;
  • Simple: no server to maintain.

Setup in 5 steps
#

  1. Create a bucket in Cloudflare R2;
  2. Bind a custom domain (e.g. r2.your-domain.com) — Cloudflare auto-creates CNAME and certificate;
  3. Create an R2 API Token (Object Read & Write, scoped to the bucket);
  4. Configure PicGo with the S3 plugin (access key, endpoint https://<account-id>.r2.cloudflarestorage.com, upload path {year}/{month}/{md5}.{extName}, urlPrefix https://r2.your-domain.com);
  5. Install the Obsidian auto-upload plugin pointed at PicGo — paste an image and the link is written back automatically.

Caching
#

R2 custom domains do not cache by default; add a Cache Rule matching image extensions with a 30-day edge TTL, so repeat visits hit the edge instead of origin.

Troubleshooting tips
#

  • Upload failing: check PicGo is running and the token is valid;
  • Old image after replacement: purge cache or append ?v=timestamp;
  • 403 on tests: use a browser User-Agent, Cloudflare blocks bare scripts as bots;
  • Data safety: R2 objects persist; if the domain lapses, keep the r2.dev fallback domain active.

Read the full Chinese article for details.

Related