in reply to Opinions on determining mime type

It's a pity that browsers/systems cannot agree on what are supposed to be "standard" MIME types. You are correct that sometimes this MIME type will be accurate and other times it will be something generic like "application/octet-stream" even though the browser and its OS know exactly what type of file it is.

File::MMagic works exactly like the 'file' Unix command. It uses a "magic" file that has identifying characteristics of tons of different file formats and can very accurately determine the type of file.

What I would do is give preference either to the browser's MIME type (if it's non-generic) or use something like File::MMagic (or perhaps both). Failing either of those, fall back to the extension and do some hard-coded mappings.