Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a generic image MIME type that modern browsers recognize?

Is there a special MIME type (e.g. application/image) that will enable the browser interpret a response as an image independent of the image type (pdf, gif, jpg)?

I have a server that automatically generates file names without extension for the uploaded images. What I want to avoid, is storing their extensions and to serve them to the clint using just the generated IDs. And I want to let the browser know it is an image, but without specifying the file extension.

like image 205
4 revs, 2 users 76% Avatar asked Nov 05 '13 00:11

4 revs, 2 users 76%


1 Answers

No, the point of the MIME types is to identify the types of resources at the server level and allow the client to process them as is.

There are some image file types which do not have a binary signature marker (ex.: svg). Not having this marker makes the file hard to identify without a mimetype or file extension.

For example exif_imagetype is a function which identifies GIF, JPEG, PNG, SWF, PSD, BMP, TIFF_II, TIFF_MM, JPC, JP2, JPX, JB2, SWC, IFF, WBMP, XBM, ICO but does not identify SVG files.

SVG files are XML files which describe the image structure in shapes, lines and points. So it's a text file, without the full proper mime type declaring that it's not only an image but an SVG image, it couldn't be treated as an image.

<!-- how do we handle this if the server 
     does not give as a mime type header? -->
<img src="file.svg" />
<!-- we know it's an image but what to do
     with it -->

There are cases when css or js files are being generated using php and the extension is "*.php" and the developer hasn't set the correct "text/css" or "text/javascript" header, maybe the header is "text/plain", the browser will refuse to parse & apply them.

like image 142
Mihai Stancu Avatar answered Sep 28 '22 08:09

Mihai Stancu