Serving images from amazon s3 rails
I am storing all the images in amazon S3 at the client side i don't want to show the amazon s3 urls for that i wrote attachments_controller with the following method
def show
send_data(
open( @attachment.content.url, "rb").read,
开发者_JAVA技巧 :type => @attachment.content_content_type,
:filename => @attachment.content_file_name,
:disposition => "inline"
)
end
in the routes i added that every attachment needs to call the above action now everything is fine but the problem is everytime it is rendering it is not caching it. Please let me know how to cache it better is action cache is the appropriate way ?
Why don't you map a custom DNS name to the amazon bucket, and let amazon serve the assets for you?
References:
- https://serverfault.com/questions/172941/cname-record-for-amazon-s3-any-drawbacks
- http://www.codinghorror.com/blog/2007/03/using-amazon-s3-as-an-image-hosting-service.html
This is an answer to your questions posed in @Simone's answer.
You achieve this (with some effort) using Amazon's Cloudfront cdn.
You can link multiple distributions to a single S3 bucket, and each distribution can have up to 10 CNAME's associated with it.
Multiple CNAME Aliases
You can use more than one CNAME alias with a distribution. For example, you could have alias1.example.com and alias2.example.com both associated with your distribution's domain name. You can have up to 10 CNAME aliases per distribution. You can associate a particular CNAME alias with only one distribution.
More info is available in the developer guide.
精彩评论