Adding Mimetypes to MimetypesFileTypeMap

To answer Andrew Thompson, I think that MimetypesFileTypeMap is getting its default MIME Type definitions from /lib/resources.jar:/META-INF/mimetypes.default.

Running this code from the command line:

ClassLoader loader = Thread.currentThread().getContextClassLoader(); 
URL resource = loader.getResource("META-INF/mimetypes.default"); 
System.out.println(resource.getPath());

Yields:

file:/usr/java/jdk1.6.0_22/jre/lib/resources.jar!/META-INF/mimetypes.default

MimetypesFileTypeMap uses ClassLoader.getResource() to load the default mimetypes.


Spring provides a wrapper class which comes packed with a more updated MIME type list. You use it pretty much the same way you'd use MimetypesFileTypeMap.

import org.springframework.mail.javamail.ConfigurableMimeFileTypeMap;
...
ConfigurableMimeFileTypeMap mimeMap = new ConfigurableMimeFileTypeMap();
String contentType = mimeMap.getContentType(uploadedName);//defaults to application/octet-stream