Handling MIME is tricky... Here is some help

Mime vs Content

Basically the same thing. The content-type header in HTTP is a Mime type

Getting Mime Type or Content type from a file

Try File::Type