I’m using Rails 5. I store file data and the mime type in a PostGres database. Then I use
extension = Rack::Mime::MIME_TYPES.invert[mime_type]
to get a file extension when I return the data in a file to the user. However, if my mime type is
application/msword
The above returns “.dot” and I see this causing confusion with my unsophisticated user base because they are more used to a “.doc” extension. Is there a different mime type I can use that will give back a “.doc” extension or a different function I can use to convert mime types?
".dot" file extension has same mime type, it means word microsoft template.
All mime types are sorted alphabetically and you need always return first. Like this