Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy a file from S3 with Heroku and Rails

I need to send a file stored in S3 through my rails application hosted on heroku. I cannot use a redirect to the URL of the file on S3 as I want to send a sitemap which should be served from the same domain as the links inside.

Ideally, I would use some sort of proxy method to send the file by the rails app, at least, I can download the file in the tmp directory of heroku and send it after.

I would also send the right content-type for the file.

Do you know how can I achieve it ? What will be the best way ?

There is a rack app which is doing that but I'm not sure how to reproduce it in Rails, see the code here

Thanks for your help

like image 503
Adrien Coquio Avatar asked Jan 11 '12 00:01

Adrien Coquio


1 Answers

It looks like this:

blob =  AWS::S3::S3Object.value( filename, bucketname )
send_data( blob,
           { :type => 'image/jpg,
             :disposition => 'inline' } )

the type can be image/jpg, image/gif, etc

like image 190
elijah Avatar answered Oct 25 '22 21:10

elijah