Easy mapping between file extensions and mime types
Get Started
$ dotnet add package SimpleMimeMapReadme
SimpleMimeMap
Simple mapping between file extensions and mime types.
The dictionary representing the mapping is automatically populated based on jshttp mime-db.
Install
Usage
using SimpleMime;
var mime = SimpleMimeMap.GetMimeType(".jpeg"); // "image/jpeg"
// Note that an extension can have multiple mime types; mp4 has type application/mp4 when it does not have a video track
var allMimes = SimpleMimeMap.GetMimeTypes("https://example.com/movie.mp4"); // ["application/mp4", "video/mp4"]
// Generally the alphabetically first mime type will be returned, but some overrides are built in to match expectations
var mime2 = SimpleMimeMap.GetMimeType("mp4"); // "video/mp4"
// Mime types commonly map to multiple file extensions
var exts = SimpleMimeMap.GetExtensions("image/jpeg"); // ["jpg", "jpeg", "jpe"]
// Retrieve the first extension for the mime type
var ext = SimpleMimeMap.GetExtension("image/jpeg"); // "jpg"
// Some other useful methods:
var imageExtensions = SimpleMimeMap.GetImageExtensions(); // ["jpg", "png", ...];
Why this library?
- Programmatic update strategy from an up-to-date source; running the SimpleMimeMap.Updater project will fetch the latest mime maps and update the SimpleMimeMap.cs file
- Handling multiple mime maps per extension
- Allow accessing the dictionary directly for operations not built into the library
Publishing New Versions
- Push your changes and add a tag
- In GitHub create a new release from the tag
- The workflow action will automatically publish to the NuGet gallery