Detecção MIME em Ruby

require ‘ruby-filemagic’require ‘mime/types’file_path = ‘some_document.doc’# auto detect file’s file-typefm = FileMagic.new(FileMagic::MAGIC_MIME)mime_type = fm.file(file_path)puts mime_type> ‘application/msword; content=binary;’# detect extension by mime_typefile_extension = MIME::Types[mime_type][0].extensions[0]puts file_extension> ‘doc’

Continuar lendo