[Javascript] Finding file size using java script

Peter-Paul Koch pp.koch at gmail.com
Mon Mar 7 08:37:32 CST 2005


>             I am working on jsp's and have an issue in uploading files. I am
> allowed to upload at the max of 20MB on the server, but the issue is often
> user ignores the message and tries to upload more than 20MB. The request
> goes to the server and the server then throws an error message. This process
> however takes some time to get executed. I would like to have a client side
> validation done for the size of the file. 

That is not possible. JavaScript cannot access files on the users'
computer (or, indeed, any files except for HTML pages). Don't know
about ActiveX, but you said you can't use that anyway.

The best you can do is find the file size as soon as the user starts
uploading, and abort the uploading an display an error message when
the file size is above 20 M. I *think* that the size of the file is
sent to the server pretty early in the upload process.

I have no idea how to do that, though. Maybe a Java programmer can
give you some more advice.

-- 
-------------------------------------------------------------------
ppk, freelance web developer

Bug Report: Report bugs yourself, or comment on previously 
reported ones.
http://www.quirksmode.org/bugreports/
------------------------------------------------------------------



More information about the Javascript mailing list