reusser/laravel-cloudflare-r2

Cloudflare R2 integration for Laravel's Storage API

1.0.0 2024-03-18 02:47 UTC

This package is auto-updated.

Last update: 2024-11-08 05:31:04 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.