新手问题 Rails 怎么实现文件下载

zhurongwell · August 20, 2013 · Last by zhurongwell replied at August 20, 2013 · 7199 hits

rails 怎么实现文件下载

可以是使用 sendfile 或者 senddata 构造下载的流,在服务器上还可以配合 nginx 进行加速。

#1 楼 @jimrokliu 谢谢 我找了下 试了下 没成功,你那有没有什么资料啊

robbin 很老的 blog 就是说这个的。http://robbin.iteye.com/blog/154538

简单的用 rails 的 api 函数就行啦。 send_file(path, options = {}) http://api.rubyonrails.org/

#4 楼 @jjzxcc 为什么下载 PDF 时,直接在浏览器中显示。。有没有办法解决

@zhurongwell 不会啊,我用 chrome 是直接下载啊。 send_file 'path/to/file.pdf'

@zhurongwell 你是把 disposition 设成 'inline'了吧。

:disposition - specifies whether the file will be shown inline or downloaded. Valid values are 'inline' and 'attachment' (default).
You need to Sign in before reply, if you don't have an account, please Sign up first.