Skip to content

stantoxt/MimeMapping

 
 

Repository files navigation

MimeMapping

Nuget Nuget

Dictionary generated from the Apache Server mime.types file and the H5BP nginx mime.types file.

The Apache entries are used over others when collisions are found since they are from the official IANA registery. The others tend to use what works best for browsers or de facto standards (maybe we should use those ones instead, idk).

The lib is just a literal C# Dictionary<string, string> with over 1000 entries, and a helper method that can be passed a file path.

Example Usage

string myFile = "myimage.jpg";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(myFile);
Console.WriteLine(mimeType); // output: image/jpeg

string randomFile = "data.asdf";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(randomFile);
Console.WriteLine(mimeType); // output: application/octet-stream

string rawExtension = "json";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(rawExtension);
Console.WriteLine(mimeType); // output: application/json


// List all types..
foreach(var kp in MimeMapping.MimeTypes.TypeMap)
{
	Console.WriteLine($"File extension: {kp.Key}, mime string: {kp.Value}");
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%