Rails send_file无法处理大于400mb的文件

问题描述 投票:1回答:1

我使用Helicon Zoo在Windows Server 2008计算机上设置rails应用程序。

我的问题是下载400MB以上的文件。

在我的rails应用程序中,我使用以下内容将文件发送到客户端:

应用程序/控制器/ hosted_files_controller.rb

class HostedFilesController < ApplicationController
  before_filter :authenticate_user!
  around_filter :catch_not_foun

  def download
    @footprint = UserAbility.new(current_user).footprints.find(params[:id])
    send_file path
  end

  private

    def path
      if @footprint.subpath?
        @path = "#{HOSTED_FILES_PATH}\\#{@footprint.subpath}\\#{@footprint.filename}"
      else
        @path = "#{HOSTED_FILES_PATH}\\#{@footprint.filename}"
      end
    end

    def catch_not_found
      yield
    rescue ActiveRecord::RecordNotFound
      recover_and_log "We couldn't find that record.", "No record found using the id (#{params[:id]})"
    rescue ActionController::MissingFile
      recover_and_log "We couldn't find the file on our server.", "The file was not found at the following path: #{@path}"
    end

    def recover_and_log (displayed, logged)
      logger.info "!!! Error: #{logged}"
      redirect_to root_url, alert: displayed
    end
end

我在production.rb文件中注释了config.action_dispatch.x_sendfile_header,因为我没有使用Apache或Nginx。

这适用于服务器上低于约400MB的所有文件。在我达到它之后,我从Helicon Zoo获得了500内部服务器错误,该错误说明如下:

Helicon Zoo module has caught up an error. Please see the details below.
Worker Status
The process was created
Windows error
The pipe has been ended. (ERROR CODE: 109)
Internal module error
message: ZooApplication backend read Error. 
type: ZooException
file: Jobs\JobBase.cpp
line: 566 
version: 3.1.98.508 
STDERR
Empty stderr

有谁知道发生了什么事?我不知所措。

我试过了:

  • 增加send_file上的buffer_size(不起作用)
  • 在IIS中为应用程序池使用内存设置(不起作用)
  • 将x_sendfile_header更改为X-Sendfile和X-Accel-Redirect(不起作用)

我正在考虑尝试在Windows Server上安装Apache并使用x_sendfile_header卸载将文件发送到Apache,但我害怕弄乱已经(几乎)工作的应用程序。

有没有人有任何想法如何解决这个问题?

ruby-on-rails ruby iis download heliconzoo
1个回答
0
投票

默认情况下,当前版本的Helicon Zoo Ruby应用程序安装为FastCGI Ruby Rack连接器。由于FastCGI协议是阻塞协议,因此它可能对请求超时或请求最大大小有一些限制。如果你需要发送大文件,我建议你去“Ruby 1.9 Rack over HTTP with thin”路线。我想你一直在关注Ruby on Rails (2.3.x and 3.x.x)指令。现在只需按照Ruby Rack over HTTP with Thin指令中的其他步骤操作,例如运行“gem install thin”命令并编辑web.config,如下所示:

In the < handlers> section comment out two lines that follows

< !-- Ruby 1.9 over FastCGI -->

Uncomment two lines that follows 
< !-- Ruby 1.9 over HTTP, using Thin as a back-end application server -->
In the <environmentVariables> section uncomment line 
< !-- Use this APP_WORKER with HTTP Ruby engine and Thin. Thin need to be installed.
< add name="APP_WORKER" value="GEM_HOME\bin\thin start" />

另一个解决方案,因为您已经在使用Helicon产品,将安装Helicon Ape,它在Apache中提供对X-Sendfile HTTP header (see documentation)标头的支持,并且每个服务器可以为多个站点免费提供。这个解决方案会更好,因为低级WinHTTP代码将用于发送数据,这将减少服务器的负载并提高响应速度。

© www.soinside.com 2019 - 2024. All rights reserved.