Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top