# Serving a FLV through rails

**URL:** <https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957>\
**Category:** Rails\
**Created:** [November 1, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957 "2007-11-01T18:40:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 1, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/1 "2007-11-01T18:40:53Z")

</div>

Hello list,

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!

Thanks,

Marcelo.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 1, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/2 "2007-11-01T18:57:17Z")

</div>

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!).

Thanks!

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 1, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/3 "2007-11-01T19:45:14Z")

</div>

Hey, I don’t know if you’ve seen this, but it might be informative:

[http://blog.snowonrails.com/articles/2007/05/31/how-to-build-a-mini-youtube-using-activemessaging-plugin-and-amazon-s3](http://blog.snowonrails.com/articles/2007/05/31/how-to-build-a-mini-youtube-using-activemessaging-plugin-and-amazon-s3)

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 2, 2007, 2:34am UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/4 "2007-11-02T02:34:45Z")

</div>

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.

Marcelo.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 2, 2007, 2:39am UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/5 "2007-11-02T02:39:26Z")

</div>

Marcelo de Moraes S. wrote:

> 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](http://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.

Lionel

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 2, 2007, 2:12pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/6 "2007-11-02T14:12:05Z")

</div>

Hi Marcelo,

> 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.

Check out WhooTube [1]. It does what you want!

[1]  
[http://www.nedforce.com/2007/6/11/whootube-ruby-on-rails-video-streaming-open-sourced](http://www.nedforce.com/2007/6/11/whootube-ruby-on-rails-video-streaming-open-sourced)

–  
Roderick van Domburg  
[http://www.nedforce.com](http://www.nedforce.com)

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 2, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/7 "2007-11-02T17:39:34Z")

</div>

Hi Roderick, thanks a bunch for this!

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [November 3, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/serving-a-flv-through-rails/118957/8 "2007-11-03T18:20:28Z")

</div>

I think what you’re looking for is X-Sendfile. There’s a Rails plugin  
at [http://john.guen.in/rdoc/x\_send\_file/](http://john.guen.in/rdoc/x_send_file/) and it works with an Apache  
module that you can find at [http://john.guen.in/rdoc/x\_send\_file/](http://john.guen.in/rdoc/x_send_file/).

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.

Michael  
[www.buildingwebapps.com](http://www.buildingwebapps.com)

On Nov 1, 6:38 pm, Lionel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
