简体   繁体   中英

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 . It has a huge size. I want to move it to Amazon S3 bucket and make the rails know it's there. What's the easiest way to do that?

PS I have amazon access key and secret key. Do I need anything else?

The asset_sync gem will take care of synchronizing your assets between Rails and S3. And it is compatible with Rails 4 too. 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. 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. If you are not concerned about how long it takes to load your web page then it's fine to use S3. However, most people require fast load times, especially for SEO. It is better to use a CDN, such as Cloudfront.

You could try just using fog. There's an example of using that gem with Ruby (Rails) and S3 in the documentation:

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

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