林寻找一种方式来下载一个XML文件。我使用:

file_path = 'folder/' + xml_name + '.xml'
send_file file_path, :type => "text/xml"

但总是下载我一个空文件。文件本身具有16KB数据的在它...

这是为什么?

Maechi

有帮助吗?

解决方案 2

保存的问题,但我不知道为什么。

File.open(file_path, 'r') do |f|
  send_data f.read, :type => "text/xml", :filename => "10.xml"
end

SEND_DATA工作......但由send_file不是!

其他提示

也许你必须注释掉

config.action_dispatch.x_sendfile_header = "X-Sendfile"

在production.rb

HTTP:// vijaydev。 wordpress.com/2010/12/15/rails-3-and-apache-x-sendfile/ 以解释

正如尤金说,在他的回答,在生产环境中的Rails让Apache或nginx的与X-sendfile的发送实际的文件给你,如果你不任一使用的基础设施,轨道,你必须注释掉在

所建议的线
  

配置/环境/ production.rb文件。

# config.action_dispatch.x_sendfile_header = "X-Sendfile"

您必须启用./config/environments/production.rb的sendfile用法:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

如果这行不存在(或注释),那么Rails会正确地发送的文件,但不通过Apache。

如果你正在0字节的文件,然后确保你已经安装了mod_xsendfile,它可以从 https://开头tn123.org/mod_xsendfile

下载单个源文件(mod_xsendfile.c)并对其进行编译(apxs -cia mod_xsendfile.c)。你可能想运行apxs为根,以便它将正确地设置了一切。

然后你将要设置在你的Apache配置文件XSendFileXSendFilePath选项。请参阅上述URL的帮助获得更多信息。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top