Visit project on GitHub
Set theme to dark

Denoflare ♥️ Cloudflare R2

Cloudflare recently made R2 , its cloud storage offering, generally available to all customers . 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.

We made an open-source utility worker available to do this prior to official support. 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.

This worker might still be useful for use cases where you want to run custom logic or auth over standard public buckets.

Learn more

Generate presigned URLs to your R2 items

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

R2 now supports this feature directly , and you can use denoflare r2 presign to easily generate these presigned urls.

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