Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate image upload with ImageResizer.net
    text
    copied!<p>I was wondering if anyone can help, I sent ImageResizer and email about a week ago and as yet have not received a reply about my query. So hopefully someone from ImageResizer or a Stackoverflow member can answer my question.</p> <p>I have the following code.</p> <pre><code>if (File != null &amp;&amp; File.ContentLength &gt; 0) { string extension = Path.GetExtension(File.FileName.ToLower()); var imageId = Guid.NewGuid(); if (extension == ".png" || extension== ".jpg" || extension == ".jpeg" || extension == ".gif") { var i = new ImageResizer.ImageJob(File, "~/uploads/" + imageId + ".&lt;ext&gt;", new ImageResizer.ResizeSettings("width=200;height=200;format=png;mode=max")) { CreateParentDirectory = false }; i.Build(); GetValue(model, imageId); return RedirectToAction("RegisterStepTwo", "Account"); // } // TempData["WrongImageFormat"] = "Image must be either png, jpeg/jpg or gif"; // return View(); } TempData["WrongImageFormat"] = "Image must be either png, jpeg/jpg or gif"; return View(); } </code></pre> <p>What I have read over the last week on this website and others is that to try and validate against an invalid image upload, change file name, resize and change extension.</p> <p>The code above seems to do that, and I add my own Guid to add to database. If I create a invalid file in notepad add javascript and save it as a png, it returns the following error.</p> <pre><code>[ImageCorruptedException (0x80004005): File may be corrupted, empty, or may contain a PNG image with a single dimension greater than 65,535 pixels.] </code></pre> <p>So my question is, does the code above protect against invalid image uploads. Having read the docs <a href="http://imageresizing.net/docs/best-practices" rel="nofollow">here</a> and else where on the website I cannot find the information I require.</p> <p>Hopefully someone with a lot more experience than me can help with this question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload