This project is not covered by Drupal’s security advisory policy.

Overview

Flysystem Cloudflare R2 provides a Cloudflare R2 storage adapter for the
Drupal Flysystem module. It builds on the Flysystem S3 adapter and registers
an r2 Flysystem driver for storing Drupal-managed files in a
Cloudflare R2 bucket.

Cloudflare R2 exposes an S3-compatible API, but it does not implement every
AWS S3 operation exactly the same way. This module adapts the existing
Flysystem S3 integration for R2 and handles R2's unsupported object ACL
visibility lookup by returning the configured default visibility.

Features

  • Provides a Flysystem adapter plugin with the driver ID r2.
  • Uses Cloudflare R2's S3-compatible API endpoint.
  • Supports public and private Flysystem stream wrappers.
  • Inherits most configuration options from flysystem_s3.
  • Works with Drupal's file system settings and Flysystem stream wrappers.

Requirements

  • Drupal Flysystem
  • Flysystem S3
  • A Cloudflare R2 bucket
  • Cloudflare R2 S3 API credentials

Installation

Install the module and its dependencies with Composer:

composer require drupal/flysystem_cloudflare_r2
drush en flysystem flysystem_s3 flysystem_cloudflare_r2

Configuration

Configure Flysystem stream wrappers in settings.php. The stream
wrapper scheme name must not contain underscores.

$schemes = [
  'r2-public' => [
    'driver' => 'r2',
    'config' => [
      'key' => '[cloudflare-r2-access-key-id]',
      'secret' => '[cloudflare-r2-secret-access-key]',
      'region' => 'auto',
      'bucket' => '[bucket-name]',
      'endpoint' => 'https://[account-id].r2.cloudflarestorage.com',
      'public' => TRUE,
    ],
      'cache' => TRUE,
  ],
];

$settings['flysystem'] = $schemes;

After configuring the stream wrapper, select it on Drupal's file system
settings page at /admin/config/media/file-system.

Cloudflare R2 Notes

  • Use region value auto.
  • Use the endpoint format https://[account-id].r2.cloudflarestorage.com.
  • For private buckets, omit public or set it to FALSE.
  • For public buckets or CDN-backed buckets, set public to TRUE and configure a public bucket URL or custom domain as needed.

Related Modules

Supporting organizations: 

Project information

Releases