R2 Gateway: Cost-Controlled S3-Compatible Object Storage Gateway
· Tech · Tech

Since my VPS has limited storage, I recently explored object storage solutions. I found that Cloudflare R2 offers a free tier, but it doesn’t provide a reliable way to automatically stop usage once billing thresholds are exceeded. Even with Workers, it typically relies on periodic checks, which isn’t very safe.
So I built a simple R2 gateway. All requests to R2 go through this gateway, and the server interacts with R2 via the proxied API. The gateway tracks usage for each type of operation and immediately blocks requests once limits are reached, preventing extra charges. The service is deployed with Docker for continuous operation and easy migration.
VPS空间有限,所以最近折腾了一下对象存储。无意中发现cloudflare的R2有一定免费额度,但是R2没有直接有效的超出计费直接停止的功能,即使是用worker也只能间接的持续查询,不是很保险,所以尝试写了个R2的网关。
将R2通过网关中转,服务器通过中转后的api获取信息,中转记录每类操作的访问量,到达限制直接急停,部署到docker实现持续容器化运行,方便迁移