1

In my webapp I am allowing users to Upload Videos and Pictures. I was running into Maximum Size Exceeded error and found the fix using this Maximum Request Length Exceeded

But my question is for my Images controller I want to keep a 4mb limit as default. I only want to apply the solution in the link to Video controller. Is this possible? Also is there a way to add a ModelState error to check the file size before uploading? My controller action looks like

 if (m.File == null)
        {
            ModelState.AddModelError("File", "You did not slect any file");
            return View();
        }
        if (m.File.ContentLength > 0)
        {
            var fileName = System.IO.Path.GetFileName(m.File.FileName);
            byte[] uploadedFile = new byte[m.File.InputStream.Length];
            m.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
            // ..... Savefile and return
        }

However in this action I've tried if (m.File.ContentLength > 4194304) and it returns false until the complete file is uploaded on server. So my second question is how to check the file size on server without uploading?

Community
  • 1
  • 1
Flood Gravemind
  • 3,773
  • 12
  • 47
  • 79
  • +1 Interesting question , I'm interested in hearing how to hook on the headers arriving but before the request body arrives in ASP.NET MVC (Here is [a related PHP/NodeJS](http://stackoverflow.com/q/16167935/1348195) question I answered) - amusingly with WebAPI the solution is rather simple IIRC. – Benjamin Gruenbaum Aug 30 '13 at 22:44
  • @BenjaminGruenbaum It seems there isn't a answer to this. – Flood Gravemind Aug 30 '13 at 22:53
  • Your question has answered by Roei Bahumi at http://stackoverflow.com/questions/6327965/html-upload-max-file-size-does-not-appear-to-work – Abbas Amiri Aug 31 '13 at 17:59

0 Answers0