Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zone117x/MimeMapping
Constants for (almost) all MIME types and file extensions, and method to determine MIME type of a file name.
https://github.com/zone117x/MimeMapping
Last synced: about 2 months ago
JSON representation
Constants for (almost) all MIME types and file extensions, and method to determine MIME type of a file name.
- Host: GitHub
- URL: https://github.com/zone117x/MimeMapping
- Owner: zone117x
- License: mit
- Created: 2016-11-06T21:04:19.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T15:38:54.000Z (about 2 months ago)
- Last Synced: 2024-10-26T15:26:47.706Z (about 2 months ago)
- Language: C#
- Homepage:
- Size: 423 KB
- Stars: 74
- Watchers: 4
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome - zone117x/MimeMapping - Constants for (almost) all MIME types and file extensions, and method to determine MIME type of a file name. (C\#)
README
# MimeMapping
[![Nuget](https://img.shields.io/nuget/v/MimeMapping)](https://www.nuget.org/packages/MimeMapping/)
[![Nuget](https://img.shields.io/nuget/dt/MimeMapping)](https://www.nuget.org/packages/MimeMapping/)
[![build](https://github.com/zone117x/MimeMapping/actions/workflows/build.yml/badge.svg)](https://github.com/zone117x/MimeMapping/actions/workflows/build.yml)
[![codecov](https://codecov.io/github/zone117x/MimeMapping/branch/master/graph/badge.svg)](https://codecov.io/github/zone117x/MimeMapping)Constants for (almost) all MIME types and method to determine MIME type from a file name.
Contains just over 1000 mime types.The Dictionary is generated from the [`jshttp/mime-db`](https://github.com/jshttp/mime-db#mime-db) `db.json`.
Works similar to .NET's [System.Web.MimeMapping.GetMimeMapping](https://learn.microsoft.com/dotnet/api/system.web.mimemapping.getmimemapping).It aggregates data from the following sources:
-
-
-The library is just a literal C# `Dictionary` with over 1000 entries, and a helper method that can be passed a file path.
## Example Usage
```C#
string myFile = "myimage.jpg";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(myFile);
Console.WriteLine(mimeType); // output: image/jpegstring randomFile = "data.asdf";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(randomFile);
Console.WriteLine(mimeType); // output: application/octet-streamstring 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}");
}
```