I have a file upload form that uses FileUpload control in asp.net 4.0. On my upload button i check the file that is being submitted for some restrictions like this:
FileUpload fu = new FileUpload();
if (fu.HasFile)
{
if ((extension == ".jpg") || (extension == ".png") || (extension == ".gif"))
{
if (fu.PostedFile.ContentLength <= 2MB)
{
fu.SaveAs("path"); // save the file on the server
// check file header ...
}
}
}
The problem is that when i submit a video (which obviously has a different extension and size > 2MB) instead of checking this on the client and give the error i have set up, it uploads it and then the client receives the error. Problem is what if the client submits a 1GB file?! I mean, how does it pass from extension and size validation to SaveAs(), i can't understand. Any opinions? Thanks!