Click here to Skip to main content
15,885,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have written an application which upload a file and that file is use to save on server.
Have used MVC3 with simple HTML input file control to do this.

Problem: When I upload the large file(more than 5 MB) the browser shows this page cant display. and application get crashed.

Reason : This is because the IIS is decline the request.

What I tried : I have written code in Controller to handle this condition but its not calling since IIS is not passing request to server.

Thinking : Can we have mechanism to check
1. Check the file size at client size(through jQuery, JS etc)?
2. Write code which can execute before IIS decline.
3. HTTP handler.

I just want to check the uploaded file size and there should be a prompt that user cannot upload file more than 1 MB size.

Please provide suggestions, how can I achieve this.

Thanks.
Posted
Comments
pradiprenushe 31-Oct-13 3:41am    
You cant handle request before going to iis. First increase maxRequestLength size in web.config so iis will not throw error. Then you can handle file size in page.
pradiprenushe 31-Oct-13 3:46am    
chechk this link
http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation

No, jquery is not magic, and it cannot access your file system. You can set up your web config to set a max file size, but you can't change that there will be a timeout if the file is too big. Your best bet is probably to use some sort of third party file upload control, a Flash one can check the file size on the client.
 
Share this answer
 
Refer- Check file input size with jQuery[^].
Quote:
You actually don't have access to filesystem (for example reading and writing local files), however, due to HTML5 File Api specification, there are some file properties that you do have access to, and the file size is one of them.

For the HTML bellow
HTML
<input type="file" id="myFile" />

try the following:
JavaScript
//binds to onchange event of your input field
$('#myFile').bind('change', function() {

  //this.files[0].size gets the size of your file.
  alert(this.files[0].size);
});

As it is a part of the HTML5 specification, it will only work for modern browsers (v10 required for IE) and I added here more details and links about other file information you should know: http://i.ndigo.com.br/2012/01/javascipt-checking-the-file-size/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900