2wxhkw
Last Updated: January 19, 2017
·
40
· causztic
10954763 330233280509675 1471126434 n

Setting Response Headers for aws_s3 download requests in ruby

I am using presigned urls for users to download their files from S3 and they were always opened by default by their browser and I want to override the behavior.

http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Presigner.html
According to the documents, the only parameters they accept are :expires, :virtual_host, and :secure.

However, after mucking around I realised you could set the header in the method which wasn't mentioned in the docs, like so:

client = Aws::S3::Client.new(credentials: Aws::Credentials.new(access_key, secret))
signer = Aws::S3::Presigner.new(client: client)
signer.presigned_url(:get_object, bucket: bucket, key: key, response_content_disposition: 'attachment')

No need for hacks to create a custom method for it!

Say Thanks
Respond