ByteGuard.FileValidator.AspNetCore
10.0.0
Prefix Reserved
dotnet add package ByteGuard.FileValidator.AspNetCore --version 10.0.0
NuGet\Install-Package ByteGuard.FileValidator.AspNetCore -Version 10.0.0
<PackageReference Include="ByteGuard.FileValidator.AspNetCore" Version="10.0.0" />
<PackageVersion Include="ByteGuard.FileValidator.AspNetCore" Version="10.0.0" />
<PackageReference Include="ByteGuard.FileValidator.AspNetCore" />
paket add ByteGuard.FileValidator.AspNetCore --version 10.0.0
#r "nuget: ByteGuard.FileValidator.AspNetCore, 10.0.0"
#:package ByteGuard.FileValidator.AspNetCore@10.0.0
#addin nuget:?package=ByteGuard.FileValidator.AspNetCore&version=10.0.0
#tool nuget:?package=ByteGuard.FileValidator.AspNetCore&version=10.0.0
ByteGuard.FileValidator.AspNetCore 
ByteGuard.FileValidator.AspNetCore provides first-class integration of ByteGuard.FileValidator with ASP.NET Core.
It gives you:
- Extension methods to register the file validator in the DI container
- Easy configuration via appsettings.json or fluent configuration in code
- A single, consistent way to validate uploaded files across your ASP.NET Core apps
This package is the ASP.NET Core integration layer. The core validation logic lives in ByteGuard.FileValidator.
Getting Started
Installation
This package is published and installed via NuGet.
Reference the package in your project:
dotnet add package ByteGuard.FileValidator.AspNetCore
Usage
Add to DI container
In your Program.cs (or Startup.cs in older projects), register the validator:
using ByteGuard.FileValidator.AspNetCore;
// Using inline configuration
builder.Services.AddFileValidator(options =>
{
options.AllowFileTypes(FileExtensions.Pdf, FileExtensions.Jpg, FileExtensions.Png);
options.FileSizeLimit = ByteSize.MegaBytes(25);
options.ThrowOnInvalidFiles(false);
});
// Using configuration from appsettings.json
builder.Services.AddFileValidator(options => configuration.GetSection("FileValidatorConfiguration").Bind(options));
Injection & Usage
You can then inject FileValidator into your services and other classes.
public class MyService
{
private readonly FileValidator _fileValidator;
public MyService(FileValidator fileValidator)
{
_fileValidator = fileValidator;
}
public bool SaveFile(Stream fileStream, string fileName)
{
var isValid = _fileValidator.IsValidFile(fileName, fileStream);
// ...
}
}
Configuration via appsettings
It's possible to configure the FileValidator through appsettings.json.
ℹ️ As you'll notice below, you can either define the
FileSizeLimitin raw byte size, or use theFriendlyFileSizeLimitto define the file size in a more human readable format. When both are defined,FileSizeLimitalways wins overFriendlyFileSizeLimit.
{
"FileValidatorConfiguration": {
"SupportedFileTypes": [ ".pdf", ".jpg", ".png" ],
"FileSizeLimit": 26214400,
"FriendlyFileSizeLimit": "25MB",
"ThrowExceptionOnInvalidFile": true
}
}
License
ByteGuard.FileValidator.AspNetCore is Copyright © ByteGuard Contributors - Provided under the MIT license.
| 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 is compatible. 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
- ByteGuard.FileValidator (>= 1.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
-
net8.0
- ByteGuard.FileValidator (>= 1.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
-
net9.0
- ByteGuard.FileValidator (>= 1.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 10.0.0 | 259 | 11/24/2025 |