All posts with «trick» tag

Feb 08, 2023

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'