Laravel 和 AWS Cloudfront
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39392114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel and AWS Cloudfront
提问by bernadd
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.
但是,我正在 Laravel 中做一些有趣的/私人项目,并且我想使用 Amazon S3 存储。我已经设置好了一切,并且可以正常工作,我可以使用 Laravel 文件系统将图像从我的应用程序上传到 S3,但是我想要做的是使用 CloudFront(我也设置了这个并且可以正常工作,cloudfront 是正确提供文件)用于提供图像和文件。
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?
现在我的问题是:如何将 AWS CloudFront“url”集成到 Laravel 中?我的意思是如何在 Laravel 应用程序中存储 CloudFront url?我如何检索文件 url(即图像)以便我可以在我的应用程序中显示它。我是只在数据库中存储文件路径并使用“某种特定方式”来提供完整的 url,还是将完整的 AWS CloudFront url 保存在数据库中?
How does this works at all? Sorry if the question is stupid, but I just dived into Laravel and I'm pretty new there.
这是如何运作的?对不起,如果这个问题很愚蠢,但我刚刚潜入 Laravel 并且我在那里很新。
回答by Azole
Set url to your cloudfront url in config/filesystems/s3
在 config/filesystems/s3 中将 url 设置为您的 cloudfront url
'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
它适用于 L5.5
回答by Joseph
You can use this package https://github.com/publiux/laravelcdn
你可以使用这个包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.
Laravel 的内容交付网络包
该软件包使开发人员能够使用单个 artisan 命令将其资产(或任何公共文件)上传到 CDN。然后它允许他在文件的本地版本和在线版本之间切换。