Gem 下载 PDF 会自己打开,怎么样才能只下载,不打开

ad583255925 · 2016年03月09日 · 最后由 boyishwei 回复于 2016年03月21日 · 2750 次阅读

用的 carrierwave,下载文件的时候当文件类型是 pdf,就会在新窗口打开,而不是下载,有什么办法吗

send_file ***.url

我猜你用的是 chrome 把 chrome 的 pdf 浏览功能关了吧。

如果是 send_file 的话,文档里有写如何控制,原理上是通过 Content-Disposition 响应头 取值 inline 直接打开 attachment 下载

Content-Type 不要设置成 pdf 吧

6 楼 已删除

试试在响应头里设置

Content-Disposition: attachment; filename=xxxxx.pdf

如果是 Nginx 处理的话,就要配置 Nginx,比如

location ~ ^/uploads/(.*).pdf$ {
    add_header Content-Disposition "attachment; filename=$1.pdf";
}
需要 登录 后方可回复, 如果你还没有账号请 注册新账号