Rails serving large files

杀马特。学长 韩版系。学妹 提交于 2019-12-22 22:51:52

问题


I'm developing an application serving large videos only to logged users.

To keep these videos private i put them in a private folder inside Rails project and let Rails serve them, instead of using the public folder and excluding requests from apache (to avoid direct linking to them).

My action in the controller looks like this:

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

Everything works perfectly, but just with small files, as soon as i try with real files i receive the error:

NoMemoryError (failed to allocate memory)

I read somewhere that is not a good practice to use send_file for large files, but using the other approach, to let apache serve the files, i had an issue serving files to mobile apple devices, as they're not sending the HTTP_REFERER.

Do you have any idea on how small is this memory limit? My videos are from 400MB to 2GB (trying to reduce them).

The only question i found here is without an answer serving large media files from the assets folder in rails


回答1:


I managed to activate X-Sendfile on Apache instead of letting Rails to serve large files. Working with Capistrano i found a good solution. Here is explained how Capistrano & X-Sendfile



来源:https://stackoverflow.com/questions/22099856/rails-serving-large-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!