Reputation: 6042
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
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