File.TypeChecker 3.0.0

.NET Standard 2.0
dotnet add package File.TypeChecker --version 3.0.0
NuGet\Install-Package File.TypeChecker -Version 3.0.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="File.TypeChecker" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add File.TypeChecker --version 3.0.0
#r "nuget: File.TypeChecker, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install File.TypeChecker as a Cake Addin
#addin nuget:?package=File.TypeChecker&version=3.0.0

// Install File.TypeChecker as a Cake Tool
#tool nuget:?package=File.TypeChecker&version=3.0.0

FileTypeChecker - Don't let users to inject you an invalid file

Build status

FileTypeChecker is a easy to use library that allows you to identify type of file. This will help you to validate all files that are provided by external sources.

Change log

  • Adding IFormFile extension and validations to work directly with ASP NET Core input interface.
  • Update attributes to validate multiple files and adding API that allows user to work with IFormFile directly.
  • Optimized activator usage.
  • Making sure file types only get initialized once when calling RegisterTypes after initialization has triggered.

See what is new in this version in our github release page

Why to use it?

Have you ever had a requirement for users to be able to upload files of a certain type? How do you validate that the file type is allowed? How do you protect your application from uploading a malicious file? It is standard practice to use the FileSystemInfo class provided by Microsoft and its Extension property for this kind of job, but is that enough? The answer is simple - No! This is why this small but effective library comes to help.

How it works?

FileTypeChecker use file's "magic numbers" to identify the type. According to Wikipedia this term ("magic numbers") was used for a specific set of 2-byte identifiers at the beginnings of files, but since any binary sequence can be regarded as a number, any feature of a file format which uniquely distinguishes it can be used for identification. This approach offers better guarantees that the format will be identified correctly, and can often determine more precise information about the file. See more about Magic Numbers

How to use?

using (var fileStream = File.OpenRead("myFileLocation"))
{
    var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);

    if (!isRecognizableType)
    {
        // Do something ...
    }

    IFileType fileType = FileTypeValidator.GetFileType(fileStream);
    Console.WriteLine("Type Name: {0}", fileType.Name);
    Console.WriteLine("Type Extension: {0}", fileType.Extension);
    Console.WriteLine("Is Image?: {0}", fileStream.IsImage());
    Console.WriteLine("Is Bitmap?: {0}", fileStream.Is<Bitmap>());
}

If you are interested in finding more samples please use our wiki page.

What types of file are supported?

Currently FileTypeChecker is able to identify 22 different types but also you are able to register your own types. For more information please visit our wiki page

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on File.TypeChecker:

Package Downloads
DeploySoftware.LaunchPad.Core

Shared code for LaunchPad framework.

File.TypeChecker.Web

Don't let users to inject you an invalid file! FileTypeChecker is a easy to use library that allows you to read file and recognize its type. This will help you to validate all files that is provided by external sources.

vergiCommon

Common utilities for personal projects. Mostly input-related, repetitive work that often occures in every prototype/hobby project.

Deploy.LaunchPad.Core

Shared code for LaunchPad framework.

File.TypeChecker.Async

Don't let users to inject you an invalid file! FileTypeChecker is a easy to use library that allows you to read file and recognize its type. This will help you to validate all files that is provided by external sources.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 87,373 12/16/2021
2.1.0 4,064 11/16/2021
2.0.3 418 11/11/2021
1.5.3 6,802 10/29/2021
1.5.2 17,267 8/2/2021
1.5.1 28,334 4/30/2021
1.4.0 44,722 11/24/2020
1.3.3 4,714 10/20/2020
1.3.2 4,065 10/4/2020
1.3.1 52,388 5/15/2020
1.3.0 4,479 5/7/2020
1.2.0 1,063 3/14/2020
1.1.0 392 3/7/2020
1.0.4 740 10/5/2019
1.0.3 520 10/5/2019
1.0.1 516 10/5/2019
1.0.0 716 10/4/2019