Get Extension by Mimetype in Rails

Sometimes we need to get an extension by content mime type. There are many ways to manage this but in Rails (or rack-based app) you can use this trick: Rack::Mime::MIME_TYPES.invert['image/jpeg'] # => '.jpg'

February 9, 2023 · 1 min