Home > Enterprise >  How to configure s3 filesystem for Laravel 8
How to configure s3 filesystem for Laravel 8

Time:11-07

I have worked on some older Laravel apps (5.x) which have mapped uploads to a AWS S3 disk with credentials such as:

's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],

In Laravel 8, the keys have been renamed:

's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
        'endpoint' => env('AWS_ENDPOINT'),
    ],

I was trying to map my values in a similar way (since the names didn't change much). I tried setting example-uploads-int-s3-bucket.s3.amazonaws.com and example-uploads-int-s3-bucket as the bucket (the bucket name is example-uploads-int-s3-bucket)but I was getting this error:

{"message":"Error executing \"PutObject\" on \"/example-uploads-int-s3-bucket.s3.amazonaws.com/logos/Qwsx9aUpMDkF9dEvxfN3ov9yYDDqmqKZD63m7wug.png\"; AWS HTTP error: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for /example-uploads-int-s3-bucket.s3.amazonaws.com/logos/Qwsx9aUpMDkF9dEvxfN3ov9yYDDqmqKZD63m7wug.png","context":{"userId":1,"exception":{"class":"Aws\\S3\\Exception\\S3Exception","message":"Error executing \"PutObject\" on \"/example-uploads-int-s3-bucket.s3.amazonaws.com/logos/Qwsx9aUpMDkF9dEvxfN3ov9yYDDqmqKZD63m7wug.png\"; AWS HTTP error: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for /example-uploads-int-s3-bucket.s3.amazonaws.com/logos/Qwsx9aUpMDkF9dEvxfN3ov9yYDDqmqKZD63m7wug.png","code":0,"file":"/var/www/example-site/src/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php:195","previous":{"class":"GuzzleHttp\\Exception\\RequestException","message":"cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for /example-uploads-int-s3-bucket.s3.amazonaws.com/logos/Qwsx9aUpMDkF9dEvxfN3ov9yYDDqmqKZD63m7wug.png","code":0,"file":"/var/www/example/src/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:211"}}},"level":400,"level_name":"ERROR","channel":"int","datetime":"2021-11-03T02:43:31.550758 00:00","extra":{}}

I was looking in the Laravel docs (as well as other extensive googling) but found nothing to hint to what I might be doing wrong. Can anyone give any insight?

CodePudding user response:

I finally figured it out! I had to dig down deep into the vendor library code but now I know how to configure it:

First of all, just so you can see how the endpoint is being generated:

Illuminate\Filessystem:put() ->AWSS3Adapter::upload() -> AWS\S3\ObjectUploader::upload() -> AWS\S3\ObjectUploader::promise() -> AWS\Api\Serializer::buildEndpoint()

Secondly, for the actual fix:

AWS_BUCKET=example-uploads-int-s3-bucket
AWS_URL=
AWS_ENDPOINT=https://s3.amazonaws.com
  • Related