runtime icon indicating copy to clipboard operation
runtime copied to clipboard

FileExtensionsAttribute always says invalid

Open Angelixion opened this issue 10 years ago • 4 comments

Hello, i have a property that the model always says is invalid, i have tried to not put any extensions only with [FileExtensions] but doesnt work, only works if i dont put the attribute, what i have is this.

[FileExtensions(Extensions = "png")]
public IFormFile Property { get; set; }

Angelixion avatar May 27 '16 12:05 Angelixion

Your issue is that FileExtensionAttribute considers any non-string value as invalid. An IFormFile cannot be a string, so is always invalid. See the implementation here for more

hughbe avatar Sep 02 '16 08:09 hughbe

The how i can use the FileExtensionAttribute to check an IFormFile?, and why it says FileExtensionAttribute if it doesnt check files but strings?

Angelixion avatar Sep 05 '16 07:09 Angelixion

@Angelixion The way that you use FileExtensionsAttribute only works on file names as demonstrated:

FileExtensionsAttrbibute attribute = new FileExtensionsAttribute() { Extensions = "png" };
attribute.IsValid("file.png"); // true
attribute.IsValid("file.anyotherextensions"); // false

I have no idea what IFormFile is/looks like - I suggest asking on stackoverflow.com for that

hughbe avatar Sep 05 '16 07:09 hughbe

Data Annotations Triage: At first glance this looks like an interesting request, but making it work would require more work on ASP.NET Core (maintained in http://www.github.com/aspnet/home/) than in the data annotation itself. Data annotations cannot take a dependency on Microsoft.AspNetCore.Http to make it work so the "protocol" between the attribute and IFormFile would need to use some other convention.

Our recommendation is to create a new issue in ASP.NET Core.

cc @danroth27 @DamianEdwards

divega avatar Feb 13 '17 23:02 divega