【问题标题】:Rails 3.0.x send_file sending 404 HTML instead of the real fileRails 3.0.x send_file 发送 404 HTML 而不是真实文件
【发布时间】:2012-08-10 14:37:11
【问题描述】:

我已经设置了处理特定文件下载的路由。

  match '/overview' => "pages#overview", :as => "da_overview"

在 Pages#overview 中,我用这一行发送文件

send_file File.join(Rails.root, 'public', 'downloads', 'overview.pdf'), :type =>"application/pdf"   

我已经开启了 x-sendfile 设置。

  config.action_dispatch.x_sendfile_header = "X-Sendfile"

另外,我已经在 apache 服务器中安装并启用了 mod_xsendfile 模块。我也为我的网站启用了它。

XSendFile on

不过,当我点击 url http://mysite.com/overview 时,浏览器正在下载 overview.pdf.html 并且 HTML 文件显示为 404: Requested URL /overview not found on this server

我已检查文件是否存在。 pdf 文件是 /public/downloads 目录。我缺少什么配置?请帮忙。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 apache download


    【解决方案1】:

    根据您正在运行的 mod_xsendfile 版本,您需要在“XSendFile on”之后添加以下内容之一,以授予 mod_xsendfile 访问文件系统上文件的权限。

    mod_xsendfile 0.9:

    XSendFileAllowAbove on

    mod_xsendfile >0.9:

    XSendFilePath "/path/where/files/you're/sending/are"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 2011-06-18
      • 2011-04-13
      • 2011-03-28
      • 1970-01-01
      • 2010-11-12
      • 2017-03-01
      相关资源
      最近更新 更多