Files
Backend-Api/0_Framework/Application/MaxFileSizeAttribute.cs
2024-07-05 21:36:15 +03:30

30 lines
908 B
C#

//using Microsoft.AspNetCore.Http;
//using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
//using System.ComponentModel.DataAnnotations;
//namespace _0_Framework.Application
//{
// public class MaxFileSizeAttribute : ValidationAttribute, IClientModelValidator
// {
// private readonly int _maxFileSize;
// public MaxFileSizeAttribute(int maxFileSize)
// {
// _maxFileSize = maxFileSize;
// }
// public override bool IsValid(object value)
// {
// var file = value as IFormFile;
// if (file == null) return true;
// return file.Length <= _maxFileSize;
// }
// public void AddValidation(ClientModelValidationContext context)
// {
// context.Attributes.Add("data-val", "true");
// context.Attributes.Add("data-val-maxFileSize", ErrorMessage);
// }
// }
//}