How can I check the size of an image a user is uploading? Client side first with server side double check would be the best solution.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you describe is the ultimate battle to get more information of the HttpFileUpload in HTML 2.0 specs, as that the is HTML spec you are referencing for a Form POST. Unfortunately, HttpFileUpload does not allow you to get this – not even in Javascript. It’s a very common problem.
Two solutions:
The normal solution is to change your web.config and modify the http runtime (how long to allow an upload, like 30 minutes for a big file) and the http filesize to increase the limit (default is 4 MB). This applies to Ruby/php, ASP.NET, and ASP.NET MVC – it applies to all languages as it is the HTML 2.0 spec that limits the HttpFileUpload data you can obtain on a form POST. This will allow the user to upload the entire file; and then, you would process the restrictions on your side in server code. Not the best solution; but, it is the only solution unless you use a 3rd part.
Use a 3rd party ‘file monitor’ plugin.
One of the easiest I’ve seen is RadControls by Telerik. What these controls do us they install an HttpModule, HttpHandler, and special javascript. There are several 3rd parties out there that does does, but basically this is how it works:
Here’s a demo of Telerik’s Progress Bar upload:
http://demos.telerik.com/aspnet-ajax/upload/examples/customprogress/defaultcs.aspx
Personally, I don’t like not knowing how they are locking the thread for these uploads – as I have scalability concerns when using these 3rd party tools under high use. But, for Joe Bloe’s blog, they are great tools for.
Problem w/ASP.NET MVC
The problem with these 3rd party tools is that they only work under ASP.NET WebForms – the standard ASP.NET. ASP.NET MVC removes the entire ASP.NET WebForms concept – therefore, rendering these controls useless.
Humm, perhaps there’s a new project for someone to write. 🙂