ruby on rails - How to set Content-Disposition for uploading to S3 -


i building rails 5 app uploads amazon s3 using dropzone js plugin jquery.

the upload goes fine when want view uploaded pdf in browser downloads , not display inline.

i have manually set content-disposition inline 1 of files , opens in browser instead of downloading.

i signing request , need send content header along request when creating it.

def sign     key = params[:name]     expiration = 5.minutes.from_now.utc.strftime('%y-%m-%dt%h:%m:%s.000z')     max_filesize = 5.megabytes     acl = 'public-read'     policy = base64.encode64(       "{'expiration': '#{expiration}',           'conditions': [             {'bucket': 'my-bucket'},             {'acl': '#{acl}'},             ['starts-with', '$key', '#{key}'],             ['content-length-range', 1, #{max_filesize}]           ]}         ").gsub(/\n|\r/, '')     signature = base64.encode64(openssl::hmac.digest(openssl::digest.new('sha1'), 'the_code', policy)).gsub(/\n| |\r/, '')     render json: {:awsaccesskeyid => 'the_key', :key => key, :policy => policy, :signature => signature}   end 

i have tried 403 , 400 bad request.

def sign     key = params[:name]     expiration = 5.minutes.from_now.utc.strftime('%y-%m-%dt%h:%m:%s.000z')     max_filesize = 5.megabytes     acl = 'public-read'     policy = base64.encode64(       "{'expiration': '#{expiration}',           'conditions': [             {'bucket': 'my-bucket'},             {'acl': '#{acl}'},             {'content-disposition': 'inline'},             ['starts-with', '$key', '#{key}'],             ['content-length-range', 1, #{max_filesize}]           ]}         ").gsub(/\n|\r/, '')     signature = base64.encode64(openssl::hmac.digest(openssl::digest.new('sha1'), 'the_code', policy)).gsub(/\n| |\r/, '')     render json: {:awsaccesskeyid => 'the_key', :key => key, :policy => policy, :signature => signature}   end 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -