【问题标题】:Rails serving large filesRails 处理大文件
【发布时间】:2014-04-01 17:34:33
【问题描述】:

我正在开发一个仅向登录用户提供大型视频的应用程序。

为了保持这些视频的私密性,我将它们放在 Rails 项目中的私有文件夹中,让 Rails 为它们提供服务,而不是使用公共文件夹并排除来自 apache 的请求(以避免直接链接到它们)。

我在控制器中的操作如下所示:

def video
      respond_to do |format|
        format.mp4{
         send_file File.join([Rails.root, "private/videos", @lesson.link_video1 + ".mp4"]), 
      :disposition => :inline, :stream => true
        }
      end
  end

一切都很完美,但只有小文件,一旦我尝试使用真实文件,我就会收到错误:

NoMemoryError (failed to allocate memory)

我在某处读到,将 send_file 用于大文件不是一个好习惯,但使用另一种方法,让 apache 提供文件,我在向移动苹果设备提供文件时遇到问题,因为它们没有发送HTTP_REFERER。

你知道这个内存限制有多小吗? 我的视频从 400MB 到 2GB(试图减少它们)。

我在这里找到的唯一问题是没有答案serving large media files from the assets folder in rails

【问题讨论】:

    标签: ruby-on-rails video ruby-on-rails-4 video-streaming rack


    【解决方案1】:

    我设法在 Apache 上激活了 X-Sendfile,而不是让 Rails 处理大文件。与 Capistrano 合作,我找到了一个很好的解决方案。这里解释一下Capistrano & X-Sendfile

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 2012-05-14
      • 2011-02-02
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多