Laravel and AWS Cloudfront

扶醉桌前 提交于 2019-12-12 08:46:41

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/39392114/laravel-and-aws-cloudfront

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!