Topic: Problems with Streaming and render :text => Proc.new(...)

Hello all.

I'm attempting to build a Rails site that will transcode movies on the fly into FLV format (with ffmpeg), and play them in Flash. It's just a toy for me to play with for the minute.

I've got a proof of concept working well, but I'm having problems getting render :text => Proc.new -- the method that send_file uses in its streaming mode -- to provide the data to the browser in streamed chunks. At least, that's my take on the issue.

Rather than make all this very difficult to test by giving you the code I have, I've boiled it down to a simple, similar action:

  def test_stream
    render :text => Proc.new {|response, output|
      1.upto(20) do |c|
        output.write("I have counted up to #{c}<br />\n")
        sleep 1
      end
    }
  end

This, rather than making the browser display 1 line per second, waits 20 seconds, and then delivers the whole block at once. This is, I think, the same problem I'm seeing with my transcoded movie - it all comes in one block at the end of encoding, and then starts playing, rather than streaming as it goes.

I haven't been able to find anything useful on Google; I've only been able to find people using render :text in the same manner as above.

So, does anyone have any ideas on how I resolve the problem above? Do I need to manually flush the render buffer somehow, possibly? Or, if you think I am misunderstanding the problem entirely, and there's a much better way to do this, please let me know!

Many thanks for any input you can give.

Regards,
NeilS.

Re: Problems with Streaming and render :text => Proc.new(...)

Oh, forgot to give you guys my environment: Rails 1.2.3 on Ruby 1.8.6 installed via MacPorts on OSX 10.4.10. My server is Mongrel 1.0.1, although I see the same thing with Webrick.

Cheers!