HeroKit.FileTypes
3.7.0
dotnet add package HeroKit.FileTypes --version 3.7.0
NuGet\Install-Package HeroKit.FileTypes -Version 3.7.0
<PackageReference Include="HeroKit.FileTypes" Version="3.7.0" />
<PackageVersion Include="HeroKit.FileTypes" Version="3.7.0" />
<PackageReference Include="HeroKit.FileTypes" />
paket add HeroKit.FileTypes --version 3.7.0
#r "nuget: HeroKit.FileTypes, 3.7.0"
#:package HeroKit.FileTypes@3.7.0
#addin nuget:?package=HeroKit.FileTypes&version=3.7.0
#tool nuget:?package=HeroKit.FileTypes&version=3.7.0
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 | 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 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. |
-
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.
No API changes; released with HeroKit.FileTypes.AspNetCore 3.7.0, the new ASP.NET Core integration. Documentation moved to herokit.lyconiq.com.