Discover MIME type in ColdFusion

  • Post author:
  • Post category:Uncategorized

Today I was building an email form that would include attachments. I realized that I couldn’t predict what type of file the user would attach, so I went looking for a way to auto-discover the MIME type of a file. I ended up at cflib, where I found just what I needed (thanks Ben Rogers!) This small bit of code is all I needed from his UDF:getPageContext().getServletContext().getMimeType()You just feed a file path to the getMimeType part, and it will return a MIME type that can be plugged into cfmailparam. Very cool!