Laravel-medialibrary: serve images from S3 with cloudfront/cloudflare?

Created on 3 Mar 2020  路  2Comments  路  Source: spatie/laravel-medialibrary

I want to serve my S3 images with cloudfront, I've tried to change:
'domain' => 'https://'.env('AWS_BUCKET').'.s3.amazonaws.com',
in medialibrary.php to be the link to cloudfront but it doesn't register the change. not sure what I'm doing wrong.

Most helpful comment

With 8.0 use config/filesystems.php

 '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_S3_CLOUDFRONT'),
        ],

All 2 comments

Hi,

You can do something like this (replacing the full value):

    's3' => [
        /*
         * The domain that should be prepended when generating urls.
         */
        'domain' => env('AWS_CLOUDFRONT_URL'),
    ],

Then, inside your .env file add your cloudfront url:

AWS_CLOUDFRONT_URL=https://xxxx.cloudfront.net

With 8.0 use config/filesystems.php

 '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_S3_CLOUDFRONT'),
        ],
Was this page helpful?
0 / 5 - 0 ratings