Rails的carrierwave S3获得的URL与Content-Disposition头 [英] Rails carrierwave S3 get url with Content-Disposition header

查看:245
本文介绍了Rails的carrierwave S3获得的URL与Content-Disposition头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是carrierwave + AWS S3上传的文件,我们需要提供下载功能。

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

有关解决方案1,我们使用:

For solution 1, we use:

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

和它不IE8下工作,单击该链接就会打开这个​​文件(影像)。

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

据<一href="http://stackoverflow.com/questions/17968837/file-opens-instead-of-downloading-in-internet-explorer-in-a-href-link">This,我要补充内容处置头,

然后我检查AWS的S3文件,找到我需要添加响应内容处置 file.doc.url

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

有没有什么办法可以在carrierwave做到这一点,我也可以用其他的方式?感谢您的帮助。

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

推荐答案

明白了,对于福= FileUploader.new ,我们可以使用:

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

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

阅读大量的文档和源$ C ​​$ C。

Read tons of documents and source code.

这篇关于Rails的carrierwave S3获得的URL与Content-Disposition头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆