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

zhurongwell · 2013年08月20日 · 最后由 zhurongwell 回复于 2013年08月20日 · 7198 次阅读

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).
需要 登录 后方可回复, 如果你还没有账号请 注册新账号