Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/birajmainali/ensure-file-type-dotnet
Nuget package to validate files by its content types which is more accurate.FileTypeValidator don't let users to inject you an invalid file!
https://github.com/birajmainali/ensure-file-type-dotnet
class-library content-type dotnetcore filevalidator
Last synced: about 2 months ago
JSON representation
Nuget package to validate files by its content types which is more accurate.FileTypeValidator don't let users to inject you an invalid file!
- Host: GitHub
- URL: https://github.com/birajmainali/ensure-file-type-dotnet
- Owner: BirajMainali
- Created: 2022-01-23T08:56:45.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-06T14:18:19.000Z (almost 3 years ago)
- Last Synced: 2024-11-09T14:11:58.894Z (2 months ago)
- Topics: class-library, content-type, dotnetcore, filevalidator
- Language: C#
- Homepage: https://www.nuget.org/packages/FileTypeValidator/
- Size: 11.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.
```cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.UseFileTypeValidator();
```
Di configuration for dotnet 5 project C# 10.
```cs
public void ConfigureServices(IServiceCollection services)
{
services.UseFileTypeValidator();
}
```
### UsageDependency injection
```csprivate readonly IFileTypeValidator _fileTypeValidator;
public HomeController(IFileTypeValidator fileTypeValidator)
{
_fileTypeValidator = fileTypeValidator;
}
``````cs
if (!_fileTypeValidator.IsAudio(fileName))
{
throw new Exception("Invalid file for audio");
}
```
Available methods to validate file content are `IsImage`,`IsVideo`,`IsAudio`,`IsDocument` and `IsFile`.