简体   繁体   中英

Laravel and AWS Cloudfront

I was researching and read a lot of articles on one specific topic but couldn't find relevant answers anywhere.

However I'm doing some things as a fun/private project in Laravel and I wanted to use Amazon S3 storage. I have everything set up, and it's working, I'm able to upload images to S3 from my application using Laravel Filesystem, but what I'm trying to do is use CloudFront (I have this set up and working too, the cloudfront is serving files properly) for serving images and files.

Now my question is: How to integrate AWS CloudFront "urls" into Laravel? I mean how to store CloudFront urls inside a Laravel application? How do I retrieve file urls (ie images) so I can display it inside my application. Do I store just file paths in a database and use "some specific way" to serve the full url or do I save the full AWS CloudFront urls in a database?

How does this works at all? Sorry if the question is stupid, but I just dived into Laravel and I'm pretty new there.

Set url to your cloudfront url in config/filesystems/s3

's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => 'http://xxx.cloudfront.net']

It works in L5.5

You can use this package https://github.com/publiux/laravelcdn

Content Delivery Network Package for Laravel

The package provides the developer the ability to upload his assets (or any public file) to a CDN with a single artisan command. And then it allows him to switch between the local and the online version of the files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM