ManagedCode.MimeTypes 1.0.5

Prefix Reserved
dotnet add package ManagedCode.MimeTypes --version 1.0.5
                    
NuGet\Install-Package ManagedCode.MimeTypes -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ManagedCode.MimeTypes" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ManagedCode.MimeTypes" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="ManagedCode.MimeTypes" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ManagedCode.MimeTypes --version 1.0.5
                    
#r "nuget: ManagedCode.MimeTypes, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ManagedCode.MimeTypes@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ManagedCode.MimeTypes&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=ManagedCode.MimeTypes&version=1.0.5
                    
Install as a Cake Tool

img|300x200

MimeTypes

.NET Coverage Status nuget CodeQL

Version Package Description
NuGet Package ManagedCode.MimeTypes Core library

Why MimeTypes?

MIME (Multipurpose Internet Mail Extensions) values describe the media type of a payload. They appear in HTTP headers, file upload workflows, messaging protocols and countless integrations. Unfortunately the canonical values are long strings, which makes code prone to typos and hard to validate.

ManagedCode.MimeTypes ships a generated helper with more than 1,200 extensions sourced from the jshttp/mime-db project, Apache's canonical mime.types list and curated overrides, smart heuristics for multi-part extensions (such as .tar.gz), runtime registration APIs and rich helpers for detecting and categorising data by content.

Feature overview

  • Generated extension → MIME map based on the latest mime-db dataset (plus curated compound extensions such as tar.gz, d.ts, ps1, …).
  • Rich overrides for lightweight markup and diagram DSLs (AsciiDoc, BibTeX, Org-Mode, PlantUML, Mermaid, Typst, TikZ, …) tailored for AI/document pipelines.
  • Reverse lookup API that returns the extensions known for a given MIME value.
  • Runtime registration/unregistration so applications can plug in custom corporate formats.
  • Content sniffing for common file signatures (PDF, PNG, JPEG, GIF, WebP, MP4, ZIP/OOXML, ODF, APK, etc.) with graceful handling of short or empty streams.
  • Extended categorisation enum covering document, audio/video, script, binary, multipart and message families with convenience predicates.
  • Safe-by-default mutation model powered by immutable dictionaries, configurable fallback MIME via MimeHelper.SetDefaultMimeType, and an IMimeHelper abstraction (MimeHelper.Instance) for DI scenarios.
  • CLI utility to refresh mimeTypes.json directly from mime-db or a custom source.

Quick start

using ManagedCode.MimeTypes;

// Extension based lookup (handles multi-part extensions automatically)
var gzip = MimeHelper.GetMimeType("archive.tar.gz");             // application/gzip
var typeScript = MimeHelper.GetMimeType("module.d.ts");          // application/typescript

// Content-based detection
using var stream = File.OpenRead("report.pdf");
var detected = MimeHelper.GetMimeTypeByContent(stream);           // application/pdf

// Categorisation helpers
if (MimeHelper.IsDocument(detected))
{
    // do something useful
}

// Reverse lookup
var jpegExtensions = MimeHelper.GetExtensions("image/jpeg");     // .jpeg, .jpg, .jpe

// Runtime registration (and clean-up)
MimeHelper.RegisterMimeType("acme", "application/x-acme");
var custom = MimeHelper.GetMimeType("invoice.acme");
MimeHelper.UnregisterMimeType("acme");

// Override the fallback MIME and use the DI-friendly adapter
MimeHelper.SetDefaultMimeType(MimeHelper.JSON);
IMimeHelper helper = MimeHelper.Instance;
var fallback = helper.GetMimeType("file.unknownext");             // application/json (custom fallback)

Keeping the database fresh

A small console utility is included to synchronise mimeTypes.json with upstream datasets and our curated overrides. The repository also ships a scheduled GitHub Actions workflow that runs the sync tool weekly and opens a pull request whenever new MIME definitions are published.

# Update the data file in-place
dotnet run --project ManagedCode.MimeTypes.Sync

# Provide custom sources or output
DOTNET_CLI_TELEMETRY_OPTOUT=1 dotnet run --project ManagedCode.MimeTypes.Sync -- \
    --source https://example.com/primary-mime-db.json \
    --add-source https://example.com/additional-mime-map.json \
    --output ./artifacts/mimeTypes.json

# Start with a clean slate and prefer local overrides
dotnet run --project ManagedCode.MimeTypes.Sync -- --reset-sources --prefer-remote

Running the tool re-generates the JSON file, which in turn updates the generated helper during the next build.

Installation

dotnet add package ManagedCode.MimeTypes

Contributing

Issues and PRs are welcome! Run dotnet test before sending a contribution, and feel free to use the sync utility to keep the MIME catalogue current.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on ManagedCode.MimeTypes:

Package Downloads
ManagedCode.Storage.Core

Base interfaces for ManagedCode.StorageS

ManagedCode.Storage.AspNetExtensions

Extensions for ASP.NET for Storage

ManagedCode.Storage.FileSystem

Storage for FileSystem

ManagedCode.Storage.Server

Extensions for ASP.NET for Storage

ManagedCode.Storage.Client

Extensions for ASP.NET for Storage

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 631 10/14/2025
1.0.4 164 10/12/2025
1.0.3 2,287 7/30/2025
1.0.2 6,652 2/6/2025
1.0.0 68,690 5/6/2022