cloudflare_r2fs
Store Drupal's public and private files in a Cloudflare R2 bucket instead of the local server, with image styles generated on demand and served straight from R2 or a custom domain.
This module takes over Drupal's public or private file system (or a custom scheme you choose) and stores those files in a Cloudflare R2 bucket over the S3 API. Public files are served directly from R2 or your custom domain; private files stream through Drupal with its normal access checks. Image style derivatives are generated on demand and written back to the bucket. R2 has no egress fees, so serving files this way avoids per-request bandwidth charges.
Features
- Binds a stream scheme to a managed R2 bucket: use
publicorprivateto take over Drupal's own file systems, or a custom scheme (such asmedia) for a specific use. - Public buckets serve files straight from R2 or a custom domain; private buckets stream through Drupal so access checks still apply.
- Image styles are generated on demand and written back to the bucket, then served from there.
- Requests are signed with AWS Signature Version 4; the R2 S3 keypair is read from settings.php.
- Uses a bucket defined by Cloudflare Storage, so the bucket, credentials, and public or private state are managed in one place.
Post-Installation
You configure this module by adding a mount that binds a stream scheme to a bucket. After enabling it:
- Define an R2 bucket with Cloudflare Storage, including its credential set and public or private setting.
- Add a mount and choose the stream scheme it serves:
publicorprivateto take over Drupal's default file systems, or a custom scheme such asmedia. - New uploads to that scheme are stored in R2. A public bucket serves them from R2 or your custom domain; a private bucket streams them through Drupal.
Additional Requirements
Requires Cloudflare Storage, the Cloudflare SDK and Cloudflare API modules, which Composer installs automatically, plus a Cloudflare account with R2 enabled and an R2 S3 access keypair. Install with Composer:
composer require drupal/cloudflare_r2fsWhile the suite is in alpha, require it as drupal/cloudflare_r2fs:^1.0@alpha (or set your project's minimum-stability to alpha) so the pre-stable releases resolve.
Recommended modules/libraries
Cloudflare Storage is required and defines the bucket this module serves from.
Similar projects
S3 File System stores files in Amazon S3 or S3-compatible services. This module is R2-specific and pairs with Cloudflare Storage: the bucket, its credentials, and its public or private state are managed as Drupal configuration, and public files can be served from a Cloudflare custom domain with no egress fees.
Supporting this Module
Issue reports, patches and feedback are welcome in the project's issue queue.
Community Documentation
For Cloudflare R2 and its S3 API, see Cloudflare's documentation at developers.cloudflare.com/r2.