Download file on click - Ruby on Rails

前端 未结 2 1887
北海茫月
北海茫月 2021-02-06 12:18

My application is using Rails 2 backend, Heroku for hosting, Paperclip for file uploads, and Amazon S3 for file storage.

Right now users can upload files with paperclip

2条回答
  •  天涯浪人
    2021-02-06 13:02

    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.

提交回复
热议问题