Get file extension by content type?

I’m building file upload functionality into a Phoenix application and I’m wondering if there is any way in Elixir to get the proper file extension for a file based on its content-type. Path.extname() seems to only do a string evaluation and grab the last dot and everything after. Is there a table of content-types somewhere that maps to common extensions that could be used for this?

You can use the MIME library: https://hexdocs.pm/mime/MIME.html

5 Likes