The website I’m developing has many FLV-encoded videos as it’s main
products. Currently I’m just throwing the FLVs in a public folder,
however,
the client would like more control over the serving of these files. I
don’t
want the webserver to serve it raw, I’d like a Rails controller’s action
to
serve it, something like /videos/render/1. This action would in turn
load
the FLV, process any logic (such as checking if the user has access to
it
etc) and only then serve it to the client. However, I have no clue on
how I
could possibly accomplish this. Any help would be very much appreciated!
On thing that may not have been clear, the example I gave of
/videos/render/1 would not render html with a code to embed a FLV,
instead,
it would send the actual FLV file and then the other viewer pages would
use
this URL to access the video files and not the file name as it would
have
been the case if the files were served via the webserver
(/videos/file.flv)
the point here is that I need to process logic before serving the file
something that I would like to integrate into my rails app (such as
checking
if the logged user has permissions to get this file!).
Hi Matthew, thanks for the reply - yes, I’ve seen this and it is a very
good
tutorial, however it does not show how to do what I want - serve FLV
through
Ruby/Rails. Take for example the serving of images through a script -
instead of outputing HTML, you output binary data and tell the client
(browser) that it is a image/jpg (I did it many times in PHP) - What I
would
like to know is how could I do this in Ruby/Rails.
Hi Matthew, thanks for the reply - yes, I’ve seen this and it is a
very good tutorial, however it does not show how to do what I want -
serve FLV through Ruby/Rails. Take for example the serving of images
through a script - instead of outputing HTML, you output binary data
and tell the client (browser) that it is a image/jpg (I did it many
times in PHP) - What I would like to know is how could I do this in
Ruby/Rails.
Look for the send_file method on api.rubyonrail.org. In most cases
involving large files (like FLV) it won’t be enough though. You most
likely will get huge Ruby processes lying around because of buffering.
Look for secure download plugins for mongrel or your favorite HTTP
server to solve this problem.
Hi Matthew, thanks for the reply - yes, I’ve seen this and it is a very
good
tutorial, however it does not show how to do what I want - serve FLV
through
Ruby/Rails. Take for example the serving of images through a script -
instead of outputing HTML, you output binary data and tell the client
(browser) that it is a image/jpg (I did it many times in PHP) - What I
would
like to know is how could I do this in Ruby/Rails.
This allows Rails to handle the decision to serve the file, but then
let the file itself be statically served. You definitely don’t want to
serve video files through send_file.