How to add Content-Disposition to a pre-autenticated Amazon S3 link?

After gathering the individual pieces of this puzzle, I was able to create this Ruby method that properly signs a query string url using the aws secret key My resources for this: RESTObjectGET documentation Signing and Authenticating REST Requests Also, the response back from S3 was helpful, because when I created a url with a bad signature, the response showed the string_to_sign that AWS S3 generated from deciphering the URL I generated. After a few iterations I was able to converge on the correct formatting of the string_to_sign and after that it was pretty standard stuff Here is the Ruby method: Create a signed query-string URL that supports setting response headers ############################################################################## def s3_signed_url(bucket, pathname, verb, content_md5=nil, content_type=nil, response_headers = {}) expires = Time. Now + 5.

Minutes response_headers_canonicalized = response_headers. Sort_by{|key, value| key. Downcase}.

Collect{|key, value| "#{key}=#{value}"}. Join("&"). To_s string_to_sign = "#{verb.

Upcase}\n#{content_md5}\n#{content_type}\n#{expires. To_i}\n/#{bucket}/#{pathname}? #{response_headers_canonicalized}" digest = OpenSSL::Digest::Digest.

New('sha1') hmac = OpenSSL::HMAC. Digest(digest, aws_secret_key, string_to_sign) signature = Base64. Encode64(hmac).

Chomp url = "http://s3.amazonaws.com/#{bucket}/#{pathname}?" if response_headers. Count > 0 response_headers. Each do |key, value| url += "#{key}=#{value}&" end end url += "AWSAccessKeyId=#{aws_access_key}&Expires=#{expires.

To_i}&Signature=#{CGI. Escape(signature)}"; return url end And you call the method like this: file_url_s3 = s3_signed_url(file_bucket, file_path, 'GET', nil, nil, {'response-content-disposition' => 'attachment'}).

After gathering the individual pieces of this puzzle, I was able to create this Ruby method that properly signs a query string url using the aws secret key. My resources for this: RESTObjectGET documentation Signing and Authenticating REST Requests Also, the response back from S3 was helpful, because when I created a url with a bad signature, the response showed the string_to_sign that AWS S3 generated from deciphering the URL I generated. After a few iterations I was able to converge on the correct formatting of the string_to_sign and after that it was pretty standard stuff.

Here is the Ruby method: ############################################################################## # Create a signed query-string URL that supports setting response headers ############################################################################## def s3_signed_url(bucket, pathname, verb, content_md5=nil, content_type=nil, response_headers = {}) expires = Time. Now + 5. Minutes response_headers_canonicalized = response_headers.

Sort_by{|key, value| key. Downcase}. Collect{|key, value| "#{key}=#{value}"}.

Join("&"). To_s string_to_sign = "#{verb. Upcase}\n#{content_md5}\n#{content_type}\n#{expires.

To_i}\n/#{bucket}/#{pathname}? #{response_headers_canonicalized}" digest = OpenSSL::Digest::Digest. New('sha1') hmac = OpenSSL::HMAC.

Digest(digest, aws_secret_key, string_to_sign) signature = Base64. Encode64(hmac). Chomp url = "http://s3.amazonaws.com/#{bucket}/#{pathname}?" if response_headers.

Count > 0 response_headers. Each do |key, value| url += "#{key}=#{value}&" end end url += "AWSAccessKeyId=#{aws_access_key}&Expires=#{expires. To_i}&Signature=#{CGI.

Escape(signature)}"; return url end And you call the method like this: file_url_s3 = s3_signed_url(file_bucket, file_path, 'GET', nil, nil, {'response-content-disposition' => 'attachment'}).

Thanks! The solution was indeed to add the response headers to the filename (and also use this to calculate the signature) – murze 12 hours ago.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions