user315252
user315252

Reputation: 179

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, 
         :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 ?

Upvotes: 1

Views: 1739

Answers (2)

Geoff Appleford
Geoff Appleford

Reputation: 18832

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.

Upvotes: 2

Simone Carletti
Simone Carletti

Reputation: 176352

Why don't you map a custom DNS name to the amazon bucket, and let amazon serve the assets for you?

References:

Upvotes: 3

Related Questions