Is there a bullet proof way to detect MIME type of uploaded file in Ruby or Ruby on Rails? I\'m uploading JPEGs and PNGs using SWFupload and content_type is alw
mimemagic gem will also do it
https://github.com/minad/mimemagic
from the oficial documentation
MimeMagic is a library to detect the mime type of a file by extension or by content. It uses the mime database provided by freedesktop.org (see http://freedesktop.org/wiki/Software/shared-mime-info/).
require 'mimemagic' MimeMagic.by_extension('html').text? MimeMagic.by_extension('.html').child_of? 'text/plain' MimeMagic.by_path('filename.txt') MimeMagic.by_magic(File.open('test.html')) # etc...