send_file problem with IE7. Save Image as untitled.bmp

Platform = Linux and Mongrel

I'm using send_file to send images from a controller. like this:

send_file( @content.location, :disposition => 'inline', :type => File.mime_type?(@content.location)) # mime_type? courtesy of mimetype_fu

This is called for in an ordinary <img> tag.

It all works perfectly except for one minor hitch which is driving me mad.

If you right click on the image in IE7 and choose "Save Image As..." the file save dialog always defaults the filename to "untitled.bmp".

Other browsers always get the correct file name (usually something like "61.png" or "18.jpg")

If I copy the file into the corresponding path under RAILS_ROOT/public then IE7 will get the filename correct - as will all browsers.

Interestingly if you do save the file as untitled.bmp it's a perfectly good bmp file.

The HTTP headers set by mongrel differ substantially from the ones set by send_file.

Using send_file gives:

Status=OK - 200 Date=Tue, 16 Sep 2008 18:16:59 GMT Server=Mongrel 1.1.4 Vary=Host Status=200 OK X-Runtime=0.01416 Content-Transfer-Encoding=binary Cache-Control=private Content-Disposition=inline; filename="16.jpg" Content-Type=image/jpeg Content-Length=164553 X-Cache=MISS from www.sharehost.co.uk Keep-Alive=timeout=15, max=100 Connection=Keep-Alive

Serving the file from the public area gives:

Status=OK - 200 Date=Tue, 16 Sep 2008 18:17:09 GMT Vary=Host Etag="48cfb25c-65c2f-918190" Last-Modified=Tue, 16 Sep 2008 13:19:24 GMT Content-Type=image/jpeg Content-Length=416815 X-Cache=MISS from www.sharehost.co.uk Keep-Alive=timeout=15, max=99 Connection=Keep-Alive

Anybody know what I can do about this?

Noel Walters wrote:

I'm using send_file to send images from a controller. like this:

send_file( @content.location, :disposition => 'inline', :type => File.mime_type?(@content.location)) # mime_type? courtesy of mimetype_fu

This is called for in an ordinary <img> tag.

It all works perfectly except for one minor hitch which is driving me mad.

If you right click on the image in IE7 and choose "Save Image As..." the file save dialog always defaults the filename to "untitled.bmp".

Try using send_file's :filename option.

Mark Reginald James wrote:

Noel Walters wrote:

If you right click on the image in IE7 and choose "Save Image As..." the file save dialog always defaults the filename to "untitled.bmp".

Try using send_file's :filename option.

-- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com

I already tried that but it makes no difference - the response headers are exactly the same. In fact in the one instance when explorer gets it right (when the file is served normally without using send_file) there is no content-disposition header and no mention of the filename in any of the other headers either.

Thanks anyway!

Your other solution that should work is to set the header directly that IE is parsing, Content-Disposition.

i.e.:

headers['Content-Disposition'] = "inline; filename=\"" + @filename + "\""

-Brady brady@lunardawn.ca

brady8 wrote:

Your other solution that should work is to set the header directly that IE is parsing, Content-Disposition.

i.e.:

headers['Content-Disposition'] = "inline; filename=\"" + @filename + "\""

-Brady brady@lunardawn.ca

On Sep 16, 12:28�pm, Noel Walters <rails-mailing-l...@andreas-s.net>

Thanks, but send_file already puts the correct Content-Disposition header in the response, but IE only seems to work properly when it's missing - but there are other differences in the headers, so I can't tell if that is significant or not.

Here is the response header that you get when the server sends a file from a public folder. It works properly with all the browsers I've tried