Tuesday, April 28, 2009

Coldfusion - Determine File Mime Type

Wasting time on something that *should* be a very simple task is one of my worst pet-peeves. It just burns me up.

This one, for instance, in Coldfusion when you do a CFFile Upload a file you get a boat load of matadata about the file in the CFFile and File structures. There should be a way to get that metadata again using the CFFile tag, but NOOOOOOOOO you would have to dig around in java to do that. I'm cool with that. Googling, googling... still googling. This should be more readily available. How come nobody is talking about this in coldfusion? It must be simple. An hour and a half later, one (1) site has the answer, and two answers at that! http://www.coldfusionmuse.com/index.cfm/2006/8/2/mime.types I'll blog about if no one else will. Get this around!

Here it is:

<cfset variables.contenttype = getPageContext().getServletContext().getMimeType(variables.filename)>

Or there is:

<cfset obj = createObject("java","coldfusion.util.MimeTypeUtils")>
<cfset variables.contenttype = obj.guessMimeType(variables.filename)>

Another wrap!