Jpg content type

Oshrib picture Oshrib · Sep 11, 2011 · Viewed 35.7k times · Source

I have the next content-types:

image/gif

image/png

application/vnd.ms

They all work and recognized the files (gif, png, xls)...

But what is the content-type for jpg? i know that its the type for jpeg:

image/pjpeg , image/jpeg

But it's not work for jpg.

(I use that with the code:

if (contentType == "image/JPEG") ..... 
if (contentType == "image/gif")...

For category the files by their extension. maybe there is other way to do that? not by content- type ?)

Answer

daxelrod picture daxelrod · Sep 11, 2011

Caveat: I know almost zero C#.

I suspect this is a casing issue. Try this:

if (contentType.ToLower() == "image/jpeg")

RFC1341 indicates that

The type, subtype, and parameter names are not case sensitive. For example, TEXT, Text, and TeXt are all equivalent.

This means that if contentType is coming verbatim from a user-agent, it could have any capitalization, or none at all.