File.TypeChecker.Web 1.1.1

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.

Install-Package File.TypeChecker.Web -Version 1.1.1
dotnet add package File.TypeChecker.Web --version 1.1.1
<PackageReference Include="File.TypeChecker.Web" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add File.TypeChecker.Web --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

This library will provide you with five powerful and easy to use validation attributes. They will give you the power to allow or forbid any supported type of file. For example you can restrict your users to be able to upload only images or only archives just by setting an attribute into your method or class.

All validation attributes should be used over IFormFile interface and can be used in a class over property or with method parameter.

  • AllowImageOnly: This validation attribute will restrict IFormFile to be only image format like jpg, gif, bmp, png and tiff
  • AllowArchiveOnly: This validation attribute will restrict IFormFIle to be only archive format.
  • AllowedTypes: This validation attribute will allow you to specify what types of file you want to receive from user. We advice you to use FileExtension class to specify the extension string.
  • ForbidExecutableFile: This validation attribute will forbid your users to upload executable files.
  • ForbidTypes: This validation attribute will allow you to specify what types of file you don't want to recive from user. We advice you to use FileExtension class to specify the extension string.
[HttpPost("filesUpload")]
public IActionResult UploadFiles([AllowImageOnly] IFormFile imageFile, [AllowArchiveOnly] IFormFile archiveFile)
{
    // Some cool stuf here ...
}
using FileTypeChecker.Web.Attributes;

public class InputModel
{
    [AllowImageOnly]
    public IFormFile FirstFile { get; set; }

    [AllowArchiveOnly]
    public IFormFile SecondFile { get; set; }

    [AllowedTypes(FileExtension.Bitmap)]
    public IFormFile ThirdFile { get; set; }

    [ForbidExecutableFile]
    public IFormFile FourthFile { get; set; }

    [ForbidTypes(FileExtension.Doc)]
    public IFormFile FifthFile { get; set; }
}

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

This library will provide you with five powerful and easy to use validation attributes. They will give you the power to allow or forbid any supported type of file. For example you can restrict your users to be able to upload only images or only archives just by setting an attribute into your method or class.

All validation attributes should be used over IFormFile interface and can be used in a class over property or with method parameter.

  • AllowImageOnly: This validation attribute will restrict IFormFile to be only image format like jpg, gif, bmp, png and tiff
  • AllowArchiveOnly: This validation attribute will restrict IFormFIle to be only archive format.
  • AllowedTypes: This validation attribute will allow you to specify what types of file you want to receive from user. We advice you to use FileExtension class to specify the extension string.
  • ForbidExecutableFile: This validation attribute will forbid your users to upload executable files.
  • ForbidTypes: This validation attribute will allow you to specify what types of file you don't want to recive from user. We advice you to use FileExtension class to specify the extension string.
[HttpPost("filesUpload")]
public IActionResult UploadFiles([AllowImageOnly] IFormFile imageFile, [AllowArchiveOnly] IFormFile archiveFile)
{
    // Some cool stuf here ...
}
using FileTypeChecker.Web.Attributes;

public class InputModel
{
    [AllowImageOnly]
    public IFormFile FirstFile { get; set; }

    [AllowArchiveOnly]
    public IFormFile SecondFile { get; set; }

    [AllowedTypes(FileExtension.Bitmap)]
    public IFormFile ThirdFile { get; set; }

    [ForbidExecutableFile]
    public IFormFile FourthFile { get; set; }

    [ForbidTypes(FileExtension.Doc)]
    public IFormFile FifthFile { get; set; }
}

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.1 888 5/15/2020
1.1.0 113 5/11/2020
1.0.0 157 5/9/2020