I am attempting to detect the file type of a library of files on our webserver as we are implementing code that is designed to stream files to the browser securely. Previously, the files were being stored and presented to users via a direct href.
I have attempted to do this 3 different ways, all on my local machine (which is NOT a simulated production environment):
Setting a variable to be the value of what is returned from the function getPageContext().getServletContext().getMimeType(). This detects some but not all mime types for files.
Creating an object from coldfusion.util.MimeTypeUtils and calling function guessMimeType(). This also detects some but not all mime types for files.
A cffile action="read" on files in the library. This is the solution my boss recommended, as he has used this on files with cffile action="upload" from a form (and says it works), but when I use it, the cffile structure is always blank.
Ideally, I want to retrieve the mime type of every file located on the server with 100% accuracy. The code I have written has detected approximately 99% of the files on my copy of the repo, leaving about 30 that it can't identify. Included in these are MS office files with the new -x extension, and tgz compressed files.
I am wondering if there is there a sure-fire way to detect the mime-types of any given file that exists on a server by using CF code to look at it, and will the code that's being used work on a production server where very few applications are installed? It is my understanding that the first function I referenced uses the mime-type library of the OS, and the 2nd uses a predetermined list in the java object for mime-types. Searching on Google and SO has not produced anything that tells me that CF can accurately detect file mime types on it's own, nor have I seen anything that says this can't be done.
Edit: This is on a CF8 environment.