[Javascript] Finding file size using java script

Nick Fitzsimons nick at nickfitz.co.uk
Mon Mar 7 15:23:03 CST 2005


On 7 Mar 2005, at 13:20, Abhishek_Ghosh wrote:

> Hi,
>
>             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. option is to use the following code :
>

As Peter-Paul Koch points out, you can't do anything client-side to 
establish the size of the file. When the form is submitted to the 
server, the size of the submitted data (including the size of any other 
name/value information from the form) is in the Content-Length header, 
so you may want to have a look at that and bail out if it's above your 
limit. As to whether or not the entire request stream has to be read 
before your server-side handler can bail out, this depends on the 
implementation; RFC 3785 (see [http://www.faqs.org/rfcs/rfc3875.html]) 
states that all of the uploaded data does not have to have been read 
before a CGI component starts processing the request, but it's down to 
the way your server-side component works.

Hope this helps,

Nick Fitzsimons.
-- 
Nick Fitzsimons
Web Applications Developer




More information about the Javascript mailing list