Is mime content type case sensitive?

I’ve been working with attachment_fu and have found some curious
behavior when using firefox as a browser. I’ve been following the
straightforward example that is referenced in attachment_fu’s
readme.

Simply put, I have a view/new… that accepts an image file and uses
attachment_fu in the model to store the file and thumbnail on the
filesystem. The view/index… puts up the thumbnails as “link_to”
pointing at their respective full size images. I’ve been feeding in
jpeg image files and using rmagick as the image processor.

All works as advertised as long as the filename’s type is lowercase.
i.e.:
file.jpg === good
file.JPG === bad

What happens in the good case is selecting the thumbnail link causes
the fullsize image to display in the window that previously showed the
view/index…

What happens in the bad case is selecting the link causes a dialog box
to pop up asking me what I want to do with this “JPEG Picture”
content. If I select to display it in firefox it is first downloaded
and then displayed in a new window.

NOTE: The file_thumb.JPG which corresponds to the (bad) file.JPG
displays normally on the view/index… page.

NOTE: Mugshot.find(:all) shows all records (good and bad types) to
have “image/jpeg” as content_type.

NOTE: All images (good and bad) open normally when accessed directly
from the filesystem.
i.e.:
file://…/public/mugshots/0000/0001/file.JPG works
http://localhost…/0001/file.JPG doesn’t

Since I cannot reproduce this problem with either Opera, Safari, or IE
(go figure:-), I’ve opened an issue with the firefox folks.

My question here is what is the RoR server handing firefox that is
causing it to trip up?

Environment:
Ruby version 1.8.7 (powerpc-darwin9.6.0)
RubyGems version 1.3.1
Rack version 1.0 bundled
Rails version 2.3.2
Active Record version 2.3.2
Action Pack version 2.3.2
Active Resource version 2.3.2
Action Mailer version 2.3.2
Active Support version 2.3.2
Application root /Users/rick/example/mugshots
Environment development
Database adapter sqlite3
Database schema version 20090424050842

Run either Thin or Webrick - makes no difference
Grab current attachment_fu from github

I’m ready to sit naked in the dirt and wait for inspiration - not a
pretty sight I’m sure.

Rick Lloyd wrote:

Simply put, I have a view/new… that accepts an image file and uses
attachment_fu in the model to store the file and thumbnail on the
filesystem. The view/index… puts up the thumbnails as “link_to”
pointing at their respective full size images. I’ve been feeding in
jpeg image files and using rmagick as the image processor.

All works as advertised as long as the filename’s type is lowercase.
i.e.:
file.jpg === good
file.JPG === bad

I’m not completely sure how different browsers treat this, but I do know
this: On many file systems (expecially UNIX based ones) “file.jpg” and
“file.JPG” are different files entirely since the file system itself is
case sensitive.

AFAIK according to W3C spec, mime Content-Type header (type/subtype) is
not
case sensitive. That is, image/jpeg, Image/Jpeg and image/JPEG - all
mean
the same.

I agree with Robert, I guess the issue you are having is platform and
implementation specific.

On Wed, Apr 29, 2009 at 8:03 PM, Robert W. <
[email protected]> wrote:

file.jpg === good


Anupom
http://syamantics.com


What are you doing here?? Go Race!!!
http://www.mobracer.com

All works as advertised as long as the filename’s type is lowercase.
i.e.:
file.jpg === good
file.JPG === bad

i think you are talking about file extensions, not mime type. mime
content-type for jpeg files is image/jpeg (type is image and subtype is
jpeg
not jpg) but they can have .jpeg and .jpg file extensions. extensions
are
case sensitive in *nix based systems as their file system itself is case
sensitive.

On Wed, Apr 29, 2009 at 10:51 PM, Anupom [email protected] wrote:

file.jpg === good


Anupom
http://syamantics.com


What are you doing here?? Go Race!!!
http://www.mobracer.com

I just looked at the headers associated with my problem and here’s
what I saw:


http://localhost:3000/mugshots/0000/0001/DSCN0925_thumb.jpg?1241031678

GET /mugshots/0000/0001/DSCN0925_thumb.jpg?1241031678 HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:
1.9.0.10) Gecko/2009042315 Firefox/3.0.10
Accept: image/png,image/;q=0.8,/;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,
;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:3000/mugshots
Cookie: _mugshots_session=BAh7CDo…
If-Modified-Since: Wed, 29 Apr 2009 19:01:18 GMT
Cache-Control: max-age=0

HTTP/1.x 200 OK
Last-Modified: Wed, 29 Apr 2009 19:01:18 GMT
Content-Type: image/jpeg
Content-Length: 2780
Connection: keep-alive
Server: thin 1.0.0 codename That’s What She Said

http://localhost:3000/mugshots/0000/0003/DSCN0913_thumb.JPG?1241031709

GET /mugshots/0000/0003/DSCN0913_thumb.JPG?1241031709 HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:
1.9.0.10) Gecko/2009042315 Firefox/3.0.10
Accept: image/png,image/;q=0.8,/;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,
;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:3000/mugshots
Cookie: _mugshots_session=BAh7CDo…
If-Modified-Since: Wed, 29 Apr 2009 19:01:49 GMT
Cache-Control: max-age=0

HTTP/1.x 200 OK
Last-Modified: Wed, 29 Apr 2009 19:01:49 GMT
Content-Type: text/plain
Content-Length: 4812
Connection: keep-alive
Server: thin 1.0.0 codename That’s What She Said

NOTE: content_type for .jpg file is image/jpeg
NOTE: content_type for .JPG file is text/plain

Unix file command for these files tells me:
DSCN0913.JPG: JPEG image data, EXIF standard 2.2
DSCN0925.jpg: JPEG image data, EXIF standard 2.2

And Mugshot.find(:all) yields:

Mugshot.find(:all)
=> [#<Mugshot id: 1, parent_id: nil, content_type: “image/jpeg”,
filename: “DSCN0925.jpg”, thumbnail: nil, size: 818302, width: 640,
height: 479, created_at: “2009-04-29 19:01:17”, updated_at:
“2009-04-29 19:01:17”>, #<Mugshot id: 2, parent_id: 1, content_type:
“image/jpeg”, filename: “DSCN0925_thumb.jpg”, thumbnail: “thumb”,
size: 75300, width: 100, height: 75, created_at: “2009-04-29
19:01:18”, updated_at: “2009-04-29 19:01:18”>, #<Mugshot id: 3,
parent_id: nil, content_type: “image/jpeg”, filename: “DSCN0913.JPG”,
thumbnail: nil, size: 833312, width: 640, height: 479, created_at:
“2009-04-29 19:01:48”, updated_at: “2009-04-29 19:01:48”>, #<Mugshot
id: 4, parent_id: 3, content_type: “image/jpeg”, filename:
“DSCN0913_thumb.JPG”, thumbnail: “thumb”, size: 162513, width: 100,
height: 75, created_at: “2009-04-29 19:01:49”, updated_at: “2009-04-29
19:01:49”>]

I think there’s a dead moth somewhere in this soup…

Yes I agree, my problem is with file extensions and is platform
specific but I’ld like to understand it so I can get a fix.

So in the time since I wrote the original post, I’ve done some more
testing. I’ve run now with the following combinations:

Browsers: Firefox (2.0.0.9, 3.0.8, 3.0.10), Safari3.2.1, Opera9.6.4,
IE5
Plugins: attachment_fu, paperclip
Servers: webrick, thin, mongrel (ruby 1.8.7 only)
Ruby: 1.8.7 and 1.9.2dev
Rails: 2.3.2
OS: OSX 10.5.6

The problem is specific to Firefox and displays only when using:

<%= link_to image_tag(photo.public_filename(:thumb)),
photo.public_filename %>

in attachment_fu, or:

<%= link_to image_tag(@photo.snap.url(:medium)), @photo.snap.url %>

in paperclip.

If the photo is named “photo.jpg” all works as expected.

If the photo is named “photo.JPG” the link image on the from end of
the link displays correctly even though it’s name is something like
“photo_thumb.JPG”. Following the link however causes firefox to
request an action to correspond to content type “JPEG Picture”.

I’ve also done a simple test where all actions are local, i.e. from
file:// rather than http:// locations. All extensions behave
correctly.

Anyone out there want to test this out on a different OS? browser?
server?