Provides a huge dictionary of file extensions to mime types.
Provides a huge dictionary of file extensions to mime types.
English | 简体中文
Provides a huge two-way mapping of file extensions to mime types and mime types to file extensions, e.g.:
...
{".jpe", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".jpg", "image/jpeg"},
{".js", "application/javascript"},
{".json", "application/json"},
...Most mime types that have multiple possible extensions are pre-defined to get the most common extension when looking
up extension by mime type. Since multiple extensions can map to the same mime type, it is not necessary that GetExtension(GetMimeType(ext)) returns the original extension - it will return the most common extension.
Originally posted on StackOverflow here: http://stackoverflow.com/questions/1029740/get-mime-type-from-filename-extension
There are several packages on NuGet built from this repo. The official one is at this URL.
https://www.nuget.org/packages/MimeTypeMapOfficial
Note that the NuGet package sometimes lags behind the code in GitHub when there are contributions from others and I forget to update. If you find this to be the case and need some of the updates, create an issue here and I'll update NuGet.
After installation MimeTypeMap, include the following using statement in your class:
using MimeTypes;Console.WriteLine("txt -> " + MimeTypeMap.GetMimeType("txt")); // "text/plain"Pass in a string extension and get a mime type back. Optionally include the period. If not it will be added before looking up the mime type.
If no mime type is found then the generic "application/octet-stream" is returned.
Console.WriteLine("audio/wav -> " + MimeTypeMap.GetExtension("audio/wav")); // ".wav"Pass in a mime type and get an extension back. If the mime type is not registered, an error is thrown.
All code is licensed under MIT license.
Please submit pull requests for any additions while sticking to these principles for contributions:
MimeTypeMap.cs - the primary list of mime typesCONTRIBUTORS acknowledgement and fileCONTRIBUTORS file to maintain.Thank you,
Sam
No open issues yet, or sync has not completed.