Download file on click - Ruby on Rails

别来无恙 提交于 2019-12-03 03:33:23
Michael Schäfermeyer

Please try the following:

class Test < ActiveRecord::Base

  has_attached_file :testfile, 
    :storage => :s3,
    # All your S3 config
    :s3_headers => {"Content-Disposition" => "attachment"}

end

This should tell the Paperclip Gem to set the "Content-Disposition" header to the value "attachment" for newly uploaded files.

Note that you have to manually edit the already uploaded file, e.g. with Cyberduck or another FTP Client.

When you transfer the file, you need to set a Content-Disposition header with a value of attachment; filename=yourfilename.pdf. If it's transfered directly from S3, you'll need to tell S3 to set the Content-Disposition headers as well. Possibly also Content-Type.

Note that if you tell S3 to associate a Content-Disposition header, it will always transmit this header.

FWIW, here's Amazon's documentation on doing a PUT for an Object: http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!