Major Productions
Major Productions

Reputation: 6042

ASP.NET MVC 2 - Uploaded image validation - Is there more to do than checking file extensions and MIME types?

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?

Upvotes: 0

Views: 1215

Answers (1)

Christophe Geers
Christophe Geers

Reputation: 8962

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#

Upvotes: 1

Related Questions