0

I have a somewhat complex edit model coming into (surprise surprise) an Edit ActionMethod. One of the model's properties is a HttpPostedFileBase object, which I'd like to validate and display the validation results on the form if the file isn't legit. To this end, I've already started work on a custom ValidationAttribute object, based on RequiredAttribute (see How to validate uploaded file in ASP.NET MVC? for an idea of where I'm going).

Is there anything I can do in addition to checking the file extension and MIME type to ensure that, yes, the file being uploaded is indeed an image?

Community
  • 1
  • 1
Major Productions
  • 5,914
  • 13
  • 70
  • 149

1 Answers1

1

Checking the file extension or the MIME type is a start, but if you want to be sure you are dealing with a valid image you need to open the file and check its headers.

You can find more information on this in the following post:

Validate image from file in C#

Community
  • 1
  • 1
Christophe Geers
  • 8,564
  • 3
  • 37
  • 53