ManagedCode.MimeTypes
10.0.2
Prefix Reserved
See the version list below for details.
dotnet add package ManagedCode.MimeTypes --version 10.0.2
NuGet\Install-Package ManagedCode.MimeTypes -Version 10.0.2
<PackageReference Include="ManagedCode.MimeTypes" Version="10.0.2" />
<PackageVersion Include="ManagedCode.MimeTypes" Version="10.0.2" />
<PackageReference Include="ManagedCode.MimeTypes" />
paket add ManagedCode.MimeTypes --version 10.0.2
#r "nuget: ManagedCode.MimeTypes, 10.0.2"
#:package ManagedCode.MimeTypes@10.0.2
#addin nuget:?package=ManagedCode.MimeTypes&version=10.0.2
#tool nuget:?package=ManagedCode.MimeTypes&version=10.0.2

MimeTypes
| Version | Package | Description |
|---|---|---|
| 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 IANA media types registry,
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 official IANA registry plus supplemental mime-db/Apache coverage and curated compound extensions such as
tar.gz,d.ts,ps1, … - Generated MIME metadata API for IANA registration status, template URLs, references, extensions, intended usage and parseable magic-number prefixes.
- 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 anIMimeHelperabstraction (MimeHelper.Instance) for DI scenarios. - CLI utility to refresh
mimeTypes.jsonandmimeTypes.metadata.jsonfrom IANA, supplemental sources or custom sources.
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
// Registry metadata
if (MimeHelper.TryGetMimeTypeInfoByExtension("report.pdf", out var pdfInfo))
{
var template = pdfInfo.TemplateUrl; // IANA registration template URL
var magic = pdfInfo.MagicSignatures.FirstOrDefault()?.Hex; // 25 50 44 46 2D
}
// 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 and mimeTypes.metadata.json with the IANA media types registry,
supplemental upstream datasets and our curated overrides. The repository also ships a scheduled GitHub Actions workflow that runs the sync
tool weekly, validates the generated database with tests, bumps the package patch version when MIME data changes 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 -- \
--iana-source https://www.iana.org/assignments/media-types/media-types.xml \
--add-source https://example.com/additional-mime-map.json \
--output ./artifacts/mimeTypes.json \
--metadata-output ./artifacts/mimeTypes.metadata.json
# Start with a clean supplemental slate and prefer remote registry data over preserved local mappings
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 | Versions 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (12)
Showing the top 5 NuGet packages that depend on ManagedCode.MimeTypes:
| Package | Downloads |
|---|---|
|
ManagedCode.Storage.Core
Base interfaces for ManagedCode.StorageS |
|
|
ManagedCode.Storage.FileSystem
Storage for FileSystem |
|
|
ManagedCode.Storage.AspNetExtensions
Extensions for ASP.NET for Storage |
|
|
ManagedCode.MarkItDown
ManagedCode.MarkItDown converts documents, archives, and URLs into Markdown optimised for LLM and search workflows. Supports HTML, PDF, Office Open XML, EPUB, CSV, JSON, feeds, images, audio, and more with async-first APIs. |
|
|
ManagedCode.Storage.Server
Extensions for ASP.NET for Storage |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on ManagedCode.MimeTypes:
| Repository | Stars |
|---|---|
|
managedcode/Storage
Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers
|