Re: MIME types of local files
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).
--
Stanimir