Cloudflare R2 integration for Laravel's Storage API
You can install the package via composer:
composer require reusser/laravel-cloudflare-r2
Add this to the disks section of config/filesystems.php:
'r2' => [
'driver' => 'r2',
'key' => env('R2_ACCESS_KEY_ID'),
'secret' => env('R2_SECRET_ACCESS_KEY'),
'region' => env('R2_DEFAULT_REGION', 'us-east-1'),
'bucket' => env('R2_BUCKET'),
'url' => env('R2_URL'),
'endpoint' => env('R2_ENDPOINT', false),
'use_path_style_endpoint' => env('R2_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
And fill out these in your .env:
R2_URL=https://some-worker.randomid.workers.dev
R2_ENDPOINT=https://randomid.r2.cloudflarestorage.com
R2_ACCESS_KEY_ID=random-key
R2_SECRET_ACCESS_KEY=random-secret
R2_BUCKET=bucket
R2_DEFAULT_REGION=us-east-1
R2_USE_PATH_STYLE_ENDPOINT=false
Change your s3 disk to the R2 driver in config/filesystems.php:
's3' => [
'driver' => 'r2',
...
And fill out these in your .env:
AWS_URL=https://some-worker.randomid.workers.dev
AWS_ENDPOINT=https://random-id.r2.cloudflarestorage.com
AWS_ACCESS_KEY_ID=random-key
AWS_SECRET_ACCESS_KEY=random-secret
AWS_BUCKET=some-bucket
AWS_DEFAULT_REGION=us-east-1
AWS_USE_PATH_STYLE_ENDPOINT=false
No, you can use the s3
driver with Cloudflare R2, but this package makes it easier to use. Just be sure to set 'retain_visibility' => false,
in your standard s3
configuration to prevent incompatibility issues.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.