Rails 不能设置文件 header,如何实现浏览器点击下载文件?

linjunhalida · July 25, 2014 · Last by linjunhalida replied at July 25, 2014 · 2414 hits

没有办法设置文件 header 为:

Content-Type: application/octet-stream Content-Disposition: attachment;filename=\"filename.xxx\"

因为文件是放在 S3 上面的,并且是用carrierwave上传的然后我看了源码没有办法设置下载文件的参数,不然我就可以加上这个东西了:response-content-disposition

但是还要实现用户点击下载。用html a download, 不过 download 不支持 safari 以及 IE。请问大家有什么好的解决方案?

一路看源码,从 carrierwave 杀到 fog,文档一直看到 aws S3,终于找到答案了,针对一个fu = FileUploader.new,获取 url:

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

S3 的文档: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html

看了我好几个小时,真是惨啊。

You need to Sign in before reply, if you don't have an account, please Sign up first.