- Backblaze B2/Cloudflare R2: File storage
- PicGo: File upload + file compression
B2 storage offers 10GB free, and traffic between CDN alliance members is free. Access through Cloudflare Workers is basically sufficient.
1. Register Backblaze
- Create a bucket, public costs $1, so choose private
- Create application key
2. Configure Cloudflare Workers to access Backblaze B2
Official tutorial: https://www.backblaze.com/docs/cloud-storage-deliver-private-backblaze-b2-content-through-cloudflare-cdn
First install wrangler: npm install -g wrangler
Three methods to init project:
- clone template:
wrangler generate my-proxy https://github.com/backblaze-b2-samples/cloudflare-b2- this method is no longer recommended - New method:
npm create cloudflare@latest -- b2-proxy-worker, will prompt you to enter git url, but results in error “no wrangler.toml” - Most convenient might be: directly git clone, modify cp wrangler.toml
Then execute:
npm install
wrangler deploy
The workers are now successfully deployed
3. Set custom domain for workers
Method 1: Directly add in Cloudflare dashboard, workers settings
Method 2: Modify wrangler.yaml locally then deploy Note: domain cannot be placed in [vars], otherwise it won’t take effect - wasted a lot of time here
4. Set secrets instead of writing in plain text
B2_APPLICATION_KEY_ID = “xxx” B2_APPLICATION_KEY=“xxx” B2_ENDPOINT = “xxx” BUCKET_NAME = “xxx” ALLOW_LIST_BUCKET = false wrangler secret put B2_APPLICATION_KEY_ID wrangler secret put B2_APPLICATION_KEY wrangler secret put B2_ENDPOINT wrangler secret put BUCKET_NAME wrangler secret put ALLOW_LIST_BUCKET
5. Set cache
Backblaze doesn’t set cache by default, so every time Cloudflare Workers will fetch data from Backblaze source server.
Go to Backblaze backend, open bucket settings Set Bucket Info to {“cache-control”:“max-age=720000”}, meaning update every 72000s Note: Source file changes won’t update immediately, configure according to needs
Roughly recording the process