When using the S3 API, the region for an R2 bucket is auto. For compatibility with tools that do not allow you to specify a region, an empty value and us-east-1 will alias to the auto region.
Nov 19, 2022
5
Level 4
Storage via Cloudflare R2
Hi all,
I would like to use Cloudflare R2 instead of S3 to store my files. It sounds S3 compatible, so I just created a R2 file system based on S3 driver, but it seems not working.
Maybe I missed something?
filesystems.php
'r2' => [
'driver' => 's3',
'key' => env('CLOUDFLARE_R2_ACCESS_KEY'),
'secret' => env('CLOUDFLARE_R2_SECRET_KEY'),
'region' => env('CLOUDFLARE_R2_REGION'),
'bucket' => env('CLOUDFLARE_R2_BUCKET'),
'endpoint' => env('CLOUDFLARE_R2_ENDPOINT'),
'url' => env('CLOUDFLARE_R2_URL'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
.env
CLOUDFLARE_R2_ACCESS_KEY="MY_KEY"
CLOUDFLARE_R2_SECRET_KEY="MY_SECRET"
CLOUDFLARE_R2_REGION="eu-west-1"
CLOUDFLARE_R2_BUCKET="cdn-example-com"
CLOUDFLARE_R2_ENDPOINT="https://XXX.r2.cloudflarestorage.com"
CLOUDFLARE_R2_URL="https://cdn.example.com"
tinker
Storage::disk('r2')->get('A.jpg');
League\Flysystem\UnableToCheckDirectoryExistence with message 'Unable to check existence for: A.jpg'
Level 1
3 likes
Please or to participate in this conversation.