Visit project on GitHub
Set theme to dark

Denoflare ♥️ Cloudflare R2

Cloudflare recently made R2 , its cloud storage offering, available in beta to all customers .

Here are some things you can do with R2 starting with Denoflare v0.5.0 .

Easily make your R2 bucket publicly-readable on your domain

R2 has an S3-compatible API , but does not yet support the public-read ACL, although it is on their roadmap.

In the meantime, since making a bucket public for reading is so common, we've made an open-source utility worker available to do this. It's a single one-time denoflare push command to deploy it to your own account and zone (via Custom Domains for Workers ), no git commands or any other tools necessary.

Learn more

Easily make your R2 bucket readable via presigned URLs

Another common use-case for cloud storage is to make files available, but only to authenticated users via expiring URLs that are presigned.

This feature will eventually be supported in R2 directly, but in the meantime, we've made another open-source utility worker available to support this. Set up access with denoflare r2 generate-credentials, then a one-time denoflare push command to deploy it to your own account and zone (via Custom Domains for Workers ), no git commands or any other tools necessary.

Learn more

Track R2 costs and usage

Denoflare already provides analytics for Durable Objects, but we now provide similar analytics for your R2 usage and costs.

You can query daily aggregate Class A operations, Class B operations, egress, storage, associated costs, and per-bucket cost, current storage, current object count, and egress with denoflare analytics r2.

Learn more

CLI and Typescript API for all R2 operations

Interact with your R2 storage over the S3-compatible API from the new denoflare r2 command.

Each subcommand makes R2 calls via our R2 TypeScript API , available as a module or individual functions. The API is lightweight (no deps on aws-sdk or aws4fetch, only on fast-xml-parser and web standards). It can even be used within Workers themselves.

21 supported operations
- listBuckets
- headBucket
- createBucket
- deleteBucket
- getBucketEncryption
- deleteBucketEncryption
- putBucketEncryption
- getBucketLocation

- listObjects
- listObjectsV2
- getObject
- headObject
- putObject
- deleteObject
- deleteObjects
- copyObject

- createMultipartUpload
- abortMultipartUpload
- completeMultipartUpload
- uploadPart
- uploadPartCopy

Learn more

Worker R2 bucket bindings

Develop your own Cloudflare Worker scripts using Deno and strongly-typed R2Bucket environment bindings, representing the latest Cloudflare production runtime.

Run and test your worker locally (with denoflare serve) with the same R2Bucket bindings, pointing to an actual Cloudflare bucket!

How does it work?
/-------------------------\                                /------------------
|     denoflare serve     |                                |    cloudflare
|                         |                                |
|  /-------------------\  |                                |
|  |    my_worker.ts   |  |                                |
|  |         |         |  |                                |
|  |  /-------------\  |  |    /----------------------\    |  /-------------\
|  |  |  MY_BUCKET  |- |- |--->| R2 S3-compatible API |------>|  MY_BUCKET  |
|  |  \-------------/  |  |    \----------------------/    |  \-------------/
|  \-------------------/  |                                |
\-------------------------/                                |

Learn more