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

ad583255925 · March 09, 2016 · Last by boyishwei replied at March 21, 2016 · 2750 hits

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

send_file ***.url

#1 楼 @colorfulberry Cannot read file 报错

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

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

Content-Type 不要设置成 pdf 吧

6 Floor has deleted

试试在响应头里设置

Content-Disposition: attachment; filename=xxxxx.pdf

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

location ~ ^/uploads/(.*).pdf$ {
    add_header Content-Disposition "attachment; filename=$1.pdf";
}
You need to Sign in before reply, if you don't have an account, please Sign up first.