# BUG - content\_type assignment case sensitive

**URL:** <https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817>\
**Category:** Rails\
**Created:** [April 29, 2009, 9:53pm UTC](https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817 "2009-04-29T21:53:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricklach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@ricklach](https://www.ruby-forum.com/u/ricklach)\
**Post date:** [April 29, 2009, 9:53pm UTC](https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817/1 "2009-04-29T21:53:39Z")

</div>

I sent my original post to this group under the title “Is mime content  
type case sensitive”. It’s made it to page 3 and I think I’ve found a  
bug so I’m re-posting.

I have a very simple example that uses one of the attachment plugins  
to upload jpeg image files, creating thumbs on the way to storing all  
on the filesystem.

From the attachment\_fu test:

mugshots\_controller.rb has:

def index  
@mugshots = Mugshot.find(:all,  
:conditions =\> {:thumbnail =\> nil})

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @mugshots }
end

```

end

views/mugshots/index.html.erb:

# Most Wanted
\<% for mugshot in @mugshots -%\> \<%= link\_to image\_tag(mugshot.public\_filename(:thumb)), mugshot.public\_filename %\> \<% end -%\>

\<%= link\_to('New shot', { :action =\> 'new' }) %\>

mugshot.rb:

class Mugshot \< ActiveRecord::Base  
has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:size =\> 0…3.megabytes,  
:resize\_to =\> ‘640x480\>’,  
:thumbnails =\> { :thumb =\> ‘100x100\>’ }

validates\_as\_attachment

end

…\_create\_mugshots.rb:

class CreateMugshots \< ActiveRecord::Migration  
def self.up  
create\_table :mugshots do |t|  
t.column :parent\_id, :integer  
t.column :content\_type, :string  
t.column :filename, :string  
t.column :thumbnail, :string  
t.column :size, :integer  
t.column :width, :integer  
t.column :height, :integer

```
  t.timestamps
end

```

end

def self.down  
drop\_table :mugshots  
end  
end

I added two images, “DSCN0925.jpg” and “DSCN0913.JPG” through the  
application. The unix file command for these images tells me:

DSCN0913.JPG: JPEG image data, EXIF standard 2.2  
DSCN0925.jpg: JPEG image data, EXIF standard 2.2

And, using script/console, Mugshot.find(:all) gives:

> > 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”\>]

NOTE: content\_type for all four records is image/jpeg.

Observing the headers associated with a load of the view/mugshots/  
index.html.erb view with Live HTTP gives:

* * *

[http://localhost:3000/mugshots/0000/0001/DSCN0925\_thumb.jpg?1241031678](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](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](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](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: the content\_type associated with .jpg is image/jpeg  
NOTE: the content\_type associated with .JPG is text/plain

This difference causes Firefox to identify all .JPG files as “JPEG  
Picture” rather than “image/jpeg…”, resulting in different behavior  
in the browser when the “link\_to” link is followed.

Where should I take this problem?

Rick

---

<div class="post-metadata">

**Author:** ![ricklach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@ricklach](https://www.ruby-forum.com/u/ricklach)\
**Post date:** [April 29, 2009, 11:56pm UTC](https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817/2 "2009-04-29T23:56:52Z")

</div>

On Apr 29, 8:52 pm, Rick [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
\> NOTE: the content\_type associated with .jpg is image/jpeg

> NOTE: the content\_type associated with .JPG is text/plain
> 
> This difference causes Firefox to identify all .JPG files as “JPEG  
> Picture” rather than “image/jpeg…”, resulting in different behavior  
> in the browser when the “link\_to” link is followed.
> 
> Where should I take this problem?

Well if it is a rails problem, I’d post to the rails core list. Are  
you sure it is though? who serves up that image (ie does the request  
for bla/…/foo.JPG go through rails at all ? if it doesn’t it can  
hardly be rails’ fault). You may find that it is actually thin mis-  
reporting the content-type (and i’m pretty sure there’s no way it  
checks in the database to see what the content\_type of the file is).

Fred

---

<div class="post-metadata">

**Author:** ![ricklach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@ricklach](https://www.ruby-forum.com/u/ricklach)\
**Post date:** [April 30, 2009, 1:00am UTC](https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817/3 "2009-04-30T01:00:03Z")

</div>

Hello Frederick,

Here’s how I’ve tested

Ruby 1.8.7 (2008-08-11 patchlevel 72) [powerpc-darwin9.6.0]  
Rails 2.3.2  
Webrick  
Thin 1.0.0  
Mongrel 1.1.5  
rmagick 2.9.1  
ImageMagick 6.5.1  
attachment\_fu - current version  
paperclip - current version

and

Ruby 1.9.2dev (2009-04-25 trunk 23281) [powerpc-darwin9.6.0]  
Rails 2.3.2  
Webrick  
Thin 1.0.0  
rmagick 2.9.1  
ImageMagick 6.5.1  
attachment\_fu - current version  
paperclip - current version

In all cases I’m running in the development environment on a single  
machine - OSX 10.5.6 ppc.

So as near as I can tell, when I browse my Rails app at localhost:3000  
the data path is, with the exception of the \*magick and browser, all  
in the RoR world. I’m really not clear how the whole Ruby/Rails/Rack/  
[Thin, Webrick, Mongrel] thing hangs together so I can’t get any  
closer to whose problem it is, really.

I’m particularly troubled by the following:

1. attachment\_fu and paperclip have no problem identifying both .jpg  
and .JPG as image/jpeg content\_type and this information is stored in  
the database.

2. the Unix file command, looking at the files magic numbers,  
correctly identify both files as the same type - JPEG EXIF 2.2.

3. The “from” end image in the view’s link\_to displays correctly. In  
fact, I’ve checked this by using the full image at the from end  
pointing at itself on the to end.

4. Somewhere between the “click the link” and the “display the image”  
code is looking at the file name extension and assigning the  
content\_type (incorrectly) based on case.

rick

On Apr 29, 11:55 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ricklach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@ricklach](https://www.ruby-forum.com/u/ricklach)\
**Post date:** [April 30, 2009, 9:11am UTC](https://www.ruby-forum.com/t/bug-content-type-assignment-case-sensitive/166817/4 "2009-04-30T09:11:06Z")

</div>

On Apr 29, 11:59 pm, Rick [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ImageMagick 6.5.1  
> ImageMagick 6.5.1  
> closer to whose problem it is, really.  
> Rails doesn’t usually serve static content like images. have you tried  
> switching between different webservers (thin, webrick, mongrel etc.) ?

Fred
