Question

I am using Amazon S3 to store and serve user content for user accounts. I need the ability to serve the files either inline (sometimes urls for images will be in blog posts, etc) or as a download. By default when uploading a file to my S3 bucket, the file has no Content-Disposition set (which is fine because it will server inline as long as the browser recognizes the file MIME), however at times I will need to set the Content-Disposition to attachment in order to download the file.

Using Rails/S3 gem, is it possible to send a request to Amazon to specify that the file should be sent with the Content-Disposition set to attachment (or vise-versa) for just that request? Possibly it could use some sort of token (in reference to a token for the request, typically used for authenticated reads…just wondering if that can help me in this situation too)? Using the S3 gem, I know how to set and save the Content-Disposition for each file, but that would cause the file to always be downloaded and could not be used as an image inline (not tested).

Short of having two files (one with and without the Content-Disposition='download' set), any ideas? Thanks in advance.

PS I using rails Rails 2, attachment_fu and the aws-s3 gem (I can't change these because the above mentioned app is apart of a much larger, already running app and I know conflicts exist between the aws-s3 and aws_right gem)

Was it helpful?

Solution

Just in case anybody stumbles upon this old post, Amazon's API now allows for changing the Content-Disposition for files stored on S3. Read the announcement here.

OTHER TIPS

I believe the Content-Disposition is set upon upload, so if you don't want two copies of the file each with their own Content-Disposition, one way would be to stream it from a controller using send_file http://api.rubyonrails.org/classes/ActionController/Streaming.html#method-i-send_file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top