1

I tried using mimetype-fu to detect mimetypes, but it seems to work for some files, while for others it doesn't. For example, I downloaded this R manual, and I tried to detect it's mimetype, via:

File.mime_type?(File.read("R-intro.pdf"))

and it tells me that the mimetype is "unknown/unknown". Is there another way of detecting mimetypes? Is there maybe another mimetype-fu option that I'm not aware of, that could handle this case?

Geo
  • 93,257
  • 117
  • 344
  • 520
  • http://stackoverflow.com/questions/4600679/detect-mime-type-of-uploaded-file-in-ruby – apneadiving Aug 23 '12 at 15:26
  • http://api.rubyonrails.org/classes/Mime/Type.html#method-c-lookup_by_extension – apneadiving Aug 23 '12 at 15:26
  • As far as I can see, the project hasn't been updated for the past 2 years, I'll give it a try though. I don't want to stick to using extensions to guessing mimetypes. – Geo Aug 23 '12 at 16:35
  • @apneadiving, I tried `filemagic`, it did the job. Add an answer, I'll mark it! – Geo Aug 24 '12 at 10:50

1 Answers1

1

As discussed in comments, filemagic is a good fit.

apneadiving
  • 114,565
  • 26
  • 219
  • 213