Skip to content

Instantly share code, notes, and snippets.

@barlino
Created June 19, 2012 03:36
Show Gist options
  • Save barlino/2952157 to your computer and use it in GitHub Desktop.
Save barlino/2952157 to your computer and use it in GitHub Desktop.
Using the magic gem to identify file mime type
#installation
gem install magic
#example
require "magic"
Magic.guess_file_mime("CKMetrics.pdf")
#=> "application/pdf; charset=binary"
Magic.guess_file_mime_type("translate_tts.mp3")
#=> "audio/mpeg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment