MIME types of local files

R

Roedy Green

Does the concept of MIME type apply to a local file? Does the OS have
some list of extensions -> MIME type, similar to the way Tomcat does?

Does the browser ignore MIME types for file:// urls? and decide what
to do based on extension or by asking the OS?

It seems to me, logically a MIME type should be attached to a file in
a separate "fork" to use the old Mac terminology. If you ever
generate them from extensions, you might as well have used the
extension.
 
S

Stanimir Stamenkov

Sun, 03 Aug 2008 10:48:49 GMT, /Roedy Green/:
Does the concept of MIME type apply to a local file? Does the OS have
some list of extensions -> MIME type, similar to the way Tomcat does?

Does the browser ignore MIME types for file:// urls? and decide what
to do based on extension or by asking the OS?

It seems to me, logically a MIME type should be attached to a file in
a separate "fork" to use the old Mac terminology. If you ever
generate them from extensions, you might as well have used the
extension.

On Windows the MIME types are specified as "Content Type" value of
the corresponding HKCR child key named after the file extension. My
test shows all major browsers (IE, Opera, Safari and Mozilla) on
Windows honor it, but Java doesn't:

import java.io.File;
import java.net.URLConnection;

public class MIMETypeTest {

public static void main(String[] args) {
File f = new File("name.ext");
URLConnection con = f.toURI().toURL().openConnection();
System.out.println(con.getContentType());
}

}

It seems it always tries
URLConnection.guessContentTypeFromStream(InputStream), first, then
URLConnection.guessContentTypeFromName(String).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top