Rails carrierwave S3 get url with Content-Disposit

2019-07-16 19:45发布

问题:

We are using carrierwave + aws S3 to upload file, and we need provide a download function.

For solution 1, we use:

= link_to "Download", file.doc.url, download: file.original_name

And it does not work under IE8, click the link will open this file(image).

According to This, I should add Content-Disposition header,

Then I check aws S3 document, Found I need add response-content-disposition to file.doc.url,

Is there any way I can do this in carrierwave, or I could use other ways? Thanks for your help.

回答1:

Got it, for fu = FileUploader.new, we can use:

fu.url(query: {"response-content-disposition" => "attachment;"})

Read tons of documents and source code.