reusser / laravel-cloudflare-r2
Cloudflare R2 integration for Laravel's Storage API
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- league/flysystem-aws-s3-v3: ^3.25
- league/flysystem-path-prefixing: ^3.23
- league/flysystem-read-only: ^3.23
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-10-08 05:19:31 UTC
README
Cloudflare R2 integration for Laravel's Storage API
Installation
You can install the package via composer:
composer require reusser/laravel-cloudflare-r2
Option 1: Use a new Disk
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
Option 2: Use S3 Disk
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
FAQ
Is this package really necessary?
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.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.