[Mongrel] returning images from Mongrel

Dennis Sutch dennis at sutch.com
Wed Mar 28 16:06:56 EDT 2007

I've been able to use Mongrel's native API to serve up files using:

response.start do |head, out|
  head['Content-Type'] = resource.content_type
  out.write( resource.content )

This has worked well, until I attempted to serve up images.
resource.content seems to be the problem.  Usually it returns the text of
the page.  When resource.content returns an image, I've noticed that Mongrel
doesn't set the Content-Length header to the correct length for the image.
All other headers seem to be valid.

I tried passing the filename of the image using out.send_file, but it seems
as though send_file is no longer available.

What method should be used for returning binary content such as images?

Dennis Sutch
dennis at sutch.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070328/dafdfacd/attachment-0001.html 

More information about the Mongrel-users mailing list