简体   繁体   English

将Amazon S3存储桶用于Rails 4中的静态资产

[英]Using Amazon S3 bucket for static assets in Rails 4

I have a subfolder with the static (not uploaded from the users) images under assets/images/my_subfolder . 我有一个子文件夹,其中包含assets/images/my_subfolder下的静态 (不是从用户上传的)图像。 It has a huge size. 它的尺寸很大。 I want to move it to Amazon S3 bucket and make the rails know it's there. 我想将其移动到Amazon S3存储桶中,并使导轨知道它在那里。 What's the easiest way to do that? 最简单的方法是什么?

PS I have amazon access key and secret key. PS我有亚马逊访问密钥和秘密密钥。 Do I need anything else? 我还需要其他东西吗?

The asset_sync gem will take care of synchronizing your assets between Rails and S3. asset_sync gem将负责在Rails和S3之间同步资产。 And it is compatible with Rails 4 too. 而且它也与Rails 4兼容。 It does take a little bit of work to get setup but it does a lot of the heavy lifting for you that you'd normally have to do manually with the AWS gem. 进行设置确实需要一点工作,但是它会为您带来很多繁重的工作,而您通常需要使用AWS gem手动完成这些工作。 The documentation details everything you need to get it working. 该文档详细介绍了使其正常工作所需的一切。

On a side note, it is generally considered a bad idea to host static assets on S3 due to performance. 附带说明一下,由于性能原因,通常认为在S3上托管静态资产是个坏主意。 If you are not concerned about how long it takes to load your web page then it's fine to use S3. 如果您不担心加载网页需要多长时间,则可以使用S3。 However, most people require fast load times, especially for SEO. 但是,大多数人需要快速加载时间,尤其是对于SEO。 It is better to use a CDN, such as Cloudfront. 最好使用CDN,例如Cloudfront。

You could try just using fog. 您可以尝试仅使用雾气。 There's an example of using that gem with Ruby (Rails) and S3 in the documentation: 文档中有一个示例将gem与Ruby(Rails)和S3一起使用:

http://fog.io/storage/ http://fog.io/storage/

As an alternative, which might help keep the asset pipeline in tact better, you might try using CloudFront, (also from Amazon) as referred to in this post: http://www.happybearsoftware.com/use-cloudfront-and-the-rails-asset-pipeline-to-speed-up-your-app.html 作为一种替代方法,可以帮助保持资产管道的完好性,您可以尝试使用CloudFront(也来自亚马逊),如本文中所提及: http : //www.happybearsoftware.com/use-cloudfront-and-the -rails-asset-pipeline-to-speed-up-your-app.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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