HeroKit.FileTypes 3.7.0

dotnet add package HeroKit.FileTypes --version 3.7.0
                    
NuGet\Install-Package HeroKit.FileTypes -Version 3.7.0
                    
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="HeroKit.FileTypes" Version="3.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HeroKit.FileTypes" Version="3.7.0" />
                    
Directory.Packages.props
<PackageReference Include="HeroKit.FileTypes" />
                    
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 HeroKit.FileTypes --version 3.7.0
                    
#r "nuget: HeroKit.FileTypes, 3.7.0"
                    
#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 HeroKit.FileTypes@3.7.0
                    
#: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=HeroKit.FileTypes&version=3.7.0
                    
Install as a Cake Addin
#tool nuget:?package=HeroKit.FileTypes&version=3.7.0
                    
Install as a Cake Tool

HeroKit.FileTypes

Dependency-free file type detection for .NET 8 and .NET 10, Native AOT compatible.

  • Content detection by magic bytes for about 70 formats, including the ones other libraries get wrong: DOCX/XLSX/PPTX and OpenDocument inside ZIP, HEIC, AVIF and MP4 brands, WebP, JPEG XL, WebM vs. Matroska, Java class vs. Mach-O.
  • Extension and MIME mapping in both directions.
  • Content vs. extension check.
  • Safe upload check following OWASP: programs and scripts (by content and extension), hidden double extensions (a.php.jpg), invalid file names, SVG with script, macros (also in legacy DOC and XLS), size limits, allow-lists, and safe download names.
  • Extensible: register your own file types and upload rules.
dotnet add package HeroKit.FileTypes
using HeroKit.FileTypes;

FileTypes.Detect(stream)?.MimeType;             // "image/png" (reads at most 16 KB, restores the position)
FileTypes.GetMimeType("report.docx");           // "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
FileTypes.FromMimeType("image/x-icon")?.Extension; // "ico"
FileTypes.ContentMatchesExtension(bytes, "photo.jpg");

var policy = new UploadPolicy { AllowedTypes = [FileTypes.Jpeg, FileTypes.Png, FileTypes.Pdf] };
UploadCheckResult result = FileTypes.CheckUpload(file.OpenReadStream(), file.FileName, policy);
if (!result.IsSafe)
    return BadRequest(result.Message); // result.Rejection: DangerousContent, DoubleExtension, ExtensionMismatch, ...

// Or inject instances: new FileTypeRegistry(), new UploadValidator(policy, registry)

// Your own type, checked before the built-in types:
FileTypes.Register(new FileType("Sketch document", "application/x-sketch", FileTypeCategory.Document, "sketch")
{
    Detectors = [new ZipEntryDetector("document.json")],
    Parent = FileTypes.Zip,
});

Magic bytes are a first check, not a proof. For uploads, also limit the size, store files under generated names, and re-encode images or scan files when it matters.

Documentation: https://herokit.lyconiq.com/articles/file-types.html

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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on HeroKit.FileTypes:

Package Downloads
HeroKit.FluentValidation

FluentValidation rules for HeroKit: Turkish identity and tax numbers, IBAN, Turkish phone numbers, postal codes, vehicle plates, card numbers and safe file uploads.

HeroKit.FileTypes.AspNetCore

ASP.NET Core integration for HeroKit.FileTypes: safe upload checks for IFormFile, an [AllowedFileTypes] attribute for MVC and Razor Pages models, and a ValidateUploads() endpoint filter for minimal APIs that returns 400 with the reason.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.7.0 95 10/19/2026
3.6.0 48 10/19/2026
3.5.0 108 10/16/2026
3.4.0 47 10/16/2026
3.3.0 44 10/16/2026

No API changes; released with HeroKit.FileTypes.AspNetCore 3.7.0, the new ASP.NET Core integration. Documentation moved to herokit.lyconiq.com.