Is there a way to validate on the client side browser whether the size of a file being uploaded from a JSP page is over a set size limit without forcing the user to upload the entire file only to find out it was too large?
I would like to stay away from any proprietary controls or techniques like Flash or ActiveX if possible.
Thanks!
This isn't a perfect solution, but if you check the Content-Length HTTP header with request.getHeader("Content-Length")
then you can choose to not transfer the entire file.
By way of explanation, an extremely large file will not be transferred all at once. You'd have to actually open a stream representing that chunk of POST data and read from it for the entire thing to be transfered.
On the other hand, if you're worried about denial-of-service attacks, then you can't really trust the Content-Length header, because it can easily be forged. In this case, you should set a limit and stream a transfer of this file, stopping as soon as you've exceeded that limit.
Suggest you reconsider the Flash decision and take a look at the YUI Uploader, here:
http://developer.yahoo.com/yui/uploader/
Among other things, the fileSelect event will tell you the size of the selected file in bytes immediately after it is selected but before it's uploaded, so you'll be able to restrict accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With