I'm a bit confused about what the best approach is in order to access an image, which is uploaded to S3 and delivered via CloudFront and show it in a view (using the CloudFront URL). I use Laravel 5.5
and I deposited the CDN URL already to my S3 configuration:
'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' => 'https://xxxxxx.cloudfront.net/',
],
The following possibilities work
- Copy and paste the CloudFront link into the template (not the laravel way, I guess).
- Using
<img src="{{ Storage::url('assets/img/image.png') }}" />
. This one works, but is it the right approach? The problem here is, that if I change theFILESYSTEM_DRIVER
back to local I can't reference the resources in myDOCROOT/public/img
folder like I did earlier with{{ asset('img/icons/time.png') }}
, so I'm loosing flexibility - maybe I need to copy the assets toDOCROOT/storage/app/public/
which used by thelocal
driver?
I'm integrating CloudFront the first time to a Laravel app, so could someone who did that before tell me what the right approach is? Thank you very much.