开发者

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?


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#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜