Skip to content

Nuget package to validate files by its content types which is more accurate.FileTypeValidator don't let users to inject you an invalid file!

Notifications You must be signed in to change notification settings

BirajMainali/ensure-file-type-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileTypeValidator

FileTypeValidator do not allow users to inject invalid file. It validate files by its content types which is more accurate. Also it is easy to use. After using FileTypeValidator we can validate file by contact types such as Image,Audio,Video and document/text.

Configuration

Di configuration for dotnet 6 project.

  var builder = WebApplication.CreateBuilder(args);
  builder.Services.UseFileTypeValidator();

Di configuration for dotnet 5 project C# 10.

  public void ConfigureServices(IServiceCollection services) 
  {
      services.UseFileTypeValidator();
   }
        

Usage

Dependency injection

    private readonly IFileTypeValidator _fileTypeValidator;

    public HomeController(IFileTypeValidator fileTypeValidator)
    {
        _fileTypeValidator = fileTypeValidator;
    }
    if (!_fileTypeValidator.IsAudio(fileName))
        {
            throw new Exception("Invalid file for audio");
        }

Available methods to validate file content are IsImage,IsVideo,IsAudio,IsDocument and IsFile.

About

Nuget package to validate files by its content types which is more accurate.FileTypeValidator don't let users to inject you an invalid file!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages