I am writing a Rails application that serves files saved on the remote server towards the consumer.

During my situation the files are saved on S3 however the user demands the file through the Rails-application (hiding the particular URL). When the file was on my small servers local file-system, I possibly could make use of the Apache header X-Sendfile to release the Ruby process for other demands while Apache required within the task of delivering the file towards the client. However in my situation - in which the file is this is not on the neighborhood file-system, but on S3 - it appears that I am instructed to download it temporarily inside Rails before delivering it towards the client.

Is not there a means for Apache for everyone a "remote" file towards the client that's not really around the server it self. I do not mind if Apache needs to download the apply for this to operate, as lengthy when i do not have to connect the Ruby process while it is going on.

Any suggestions?

Thomas, I've similar needs/issues and i believe I'm able to answer your condition. First (and I am not 100% sure you take care of this part), hiding the S3 url isn't very difficult as Amazon . com enables you to definitely point CNAMES for your bucket and employ a custom URL rather than the amazon . com URL. To achieve that, you have to point your DNS towards the correct amazon . com URL. After I set mine up it looked like this: files.domain.com indicates files.domain.com.s3.amazonaws.com. You will want to produce the bucket using the title of the custom URL (files.domain.com within this example). How you can call that URL will change based on which jewel you utilize, but a thing of warning could be that the attachment_fu wordpress plugin I had been using was improperly delivering me to files.domain.com/files.domain.com/title_of_file.... I could not discover the setting to repair it, so an easy .sub way of the S3 area of the wordpress plugin fixed it.

Onto your other questions, to complete some rails code (like recording the hit within the db) before installing you can just do that:

def download
  file = File.find(...
  # code to record 'hit' to database
  redirect_to 3Object.url_for(file.filename, 
                              :expires_in => 3.hours)

That code will still make the file to become offered by S3, but but still provide you with the capability to run some ruby. (Obviously the above mentioned code will not work out of the box, you will have to point it towards the correct file and bucket and my amazon . com secrets are held in a config file. The above mentioned can also be while using syntax for that AWS::S3 jewel - http://amazon.rubyforge.org/).

Second, this content-Disposition: attachment problem is a little more tricky. Hopefully, you are a little simpler than mine and also the following solution can function. Presuming the item 'file' (within this example) may be the correct S3 object, you are able to set the disposition to attachment by

file.content_disposition = "attachment"

The above mentioned code could be performed following the file is available around the S3 server (unlike another headers and permissions), that is nice it is also added whenever you upload the file (syntax is dependent in your wordpress plugin). I am still looking for a method to tell S3 to transmit it as being an attachment and just when asked for (its not all time), and when you discover that, please tell me your solution. I have to have the ability to sometimes download it and in other cases save embed images (for instance) into HTML. I am not while using above pointed out redirect but fortunately it appears when you embed (like a HTML image tag) personal files using the content-disposition/attachment header, and also the browser still shows the look normally (however i haven't throughly examined that across enough browsers to transmit it within the wild).

Hope that can help! Best of luck.