send_file not working as expected

When I try to download a very large file (700MB) using send_file I get
a NoMemoryError (failed to allocate memory) error. It does look like I
am really running out of memory, because I am watching the memory grow
when this piece of code excutes. What typically happens on the client
side is that it sends only 256MB of the file to be downloaded. I am
stumped and not sure if this is a Windows, Mongrel, Rails, or ruby
issue. I thought send_file was supposed to stream a file in small
packets so file size wasn't an issue, but this doesn't seem to be the
case.

My set up is a Rails App. running on Windows Server 2003, Apache 2.2.3
w/ two Mongrel 0.3.13.3 services running.

Here is the controller code that is erring:

@document = Document.find(params[:id])
send_file(FILE_UPLOAD_ROOT + @document.url.strip)

Additionally, I have tried this:

@document = Document.find(params[:id])
fn = FILE_UPLOAD_ROOT + @document.url.strip
file_name = File.basename(fn.gsub('\\', '/')).gsub(/[^\w\.\-]/,'_')
send_file(FILE_UPLOAD_ROOT + @document.url.strip, :streaming => true,
:type => 'application/octet-stream', :disposition => 'attachment',
:filename => file_name)

Any help would be appreciated!

Mongrel buffers the Rails response to a StringIO then sends to the client when the request is finished. I recommend using the X-Sendfile: /path/to/file header with Apache2 mod_xsendfile instead of streaming from Rails.

jeremy