khellang/MimeTypes


A simple lookup from file name/extension to MIME/media type, generated from mime-db, which in turn is compiled from IANA, Apache and nginx's MIME types.

License: Apache-2.0

Language: C#

Keywords: lookup, mime, mimetypes


MimeTypes

A simple lookup from file name/extension to MIME/media type and vice versa, generated from mime-db, which in turn is compiled from IANA, Apache and nginx's MIME types.
This is a source-only package, containing a single class, MimeTypes, which will be compiled into your library/application under the root namespace.

Installation

The easiest way to get it, is to install the source package from NuGet.org.

Otherwise you could just pull the source file from GitHub.

Usage

Lookup MIME/media type for a file name/extension

Get the MIME/media type for a file name/extension by using the MimeTypes.TryGetMimeType or MimeTypes.GetMimeType methods:

if (MimeTypes.TryGetMimeType("awesome-file.json", out var mimeType))
{
    // mimeType == "application/json"
}

MimeTypes.GetMimeType("awesome-file.json"); // "application/json"

When calling GetMimeType, if a mapping for the given file extension doesn't exist, it will fall back to MimeTypes.FallbackMimeType, which is set to application/octet-stream by default.

Lookup file extension by MIME/media type

To get all available file extensions for a MIME/media type, you can call MimeTypes.GetMimeTypeExtensions. This returns back an IEnumerable<string> of all the available files types for the specified MIME/media type.

Project Statistics

Sourcerank 10
Repository Size 101 KB
Stars 87
Forks 22
Watchers 4
Open issues 5
Dependencies 0
Contributors 6
Tags 15
Created
Last updated
Last pushed

Top Contributors See all

Kristian Hellang Nikolay Bobrovskiy Martin Costello Günther Foidl Wesley A dependabot[bot]

Packages Referencing this Repo

MimeTypes
A simple lookup from file name/extension to MIME/media type and vice versa, generated from mime-d...
Latest release 2.5.2 - Updated - 87 stars

Recent Tags See all

v2.5.1 March 26, 2024
v2.5.0 March 26, 2024
v2.4.1 May 31, 2023
v2.4.0 March 29, 2022
v2.2.1 August 24, 2021
v2.1.4 August 23, 2021
v2.1.3 April 17, 2021
v2.1.2 April 12, 2021
v2.2.0 February 24, 2021
v2.1.1 December 29, 2020
v2.1.0 December 29, 2020
v2.0.2 June 16, 2020
v2.0.1 May 28, 2020
v2.0.0 May 28, 2020
v1.1.0 September 19, 2018

Something wrong with this page? Make a suggestion

Last synced: 2024-03-27 10:50:31 UTC

Login to resync this repository