[Javascript] RE: Javascript Digest, Vol 25, Issue 5

Abhishek_Ghosh Abhishek_Ghosh at satyam.com
Mon Mar 7 12:51:37 CST 2005


Paul,
	In my application the user can upload 5 files at the same time whose
collective size should not exceed 20MB and to check this on the server side
still incurs a lot of cost on the band width, which I intend to reduce. The
idea of having a client side validation with the size gives the privilege to
alert the user that the size has exceeded the limit and the request cannot
be processed any further.
	Java Script is anyway a client side programming language. So I
believe that file handling may be a proposition available with it. In this
regard I stumbled on this code piece but still the browser cannot identify
the File as a class.

Richard,
	The link that you have given to me also talks about the same File
class, but I could not find any clue how to bring it to use. However the
fileSizeChecker is not a document property but the name of the file type
input field on the JSP code that takes the full file path as the resolved
input. On property change of this field the appropriate method is called to
find the file size.

The problem still stands its ground. Can anyone provide me some update of
how to use the File class on an IE browser on a Windows operating system.

Thanx in advance

------------------------------------------------------- 
Regards, 
Abhishek Ghosh 
GEPS, GE-GDC, Satyam Computer Services Limited 
Satyam Technology Centre, 
Hyderabad - 500043 
Phone : (O)+91 40 55233562 (Extn-3062) 
             (R)+91 40 55233562 (Extn-2756) 
Mobile : +91 94408 77249 
e-mail : Abhishek_Ghosh at satyam.com 
Web : www.satyam.com 


-----Original Message-----
From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] 
Sent: Monday, March 07, 2005 1:00 PM
To: javascript at LaTech.edu
Subject: Javascript Digest, Vol 25, Issue 5

Send Javascript mailing list submissions to
	javascript at LaTech.edu

To subscribe or unsubscribe via the World Wide Web, visit
	https://lists.LaTech.edu/mailman/listinfo/javascript
or, via email, send a message with subject or body 'help' to
	javascript-request at LaTech.edu

You can reach the person managing the list at
	javascript-owner at LaTech.edu

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Javascript digest..."


Today's Topics:

   1. Finding file size using java script (Abhishek_Ghosh)
   2. Re: Finding file size using java script (Peter-Paul Koch)
   3. Re: Finding file size using java script (Richard Lewis)


----------------------------------------------------------------------

Message: 1
Date: Mon, 7 Mar 2005 18:50:03 +0530 
From: Abhishek_Ghosh <Abhishek_Ghosh at satyam.com>
Subject: [Javascript] Finding file size using java script
To: javascript at LaTech.edu
Message-ID: <A44765C986F8D411995B00B0D0795F4B3B68A627 at hhtnt002>
Content-Type: text/plain; charset="us-ascii"

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. To do this I cannot use ActiveX
objects as the business requirements strictly restricts use of ActiveX
Objects. The other option is to use the following code :

 

                                                var fileObj =
document.fileSizeChecker.fileUpload.value;

                                                var myFile = new
File(document.fileSizeChecker.fileUpload.value);

            myFile.open("r");

alert('myFile length: ' + myFile.getLength());

 

            Using the above code produces the following javascript error
"'File' is undefined". Please suggest how to bail out of this error or an
alternate method of achieving the purpose.

            Thanx in advance.

------------------------------------------------------- 
Regards, 
Abhishek Ghosh 
GEPS, GE-GDC, Satyam Computer Services Limited 
Satyam Technology Centre, 
Hyderabad - 500043 
Phone : (O)+91 40 55233562 (Extn-3062) 
             (R)+91 40 55233562 (Extn-2756) 
Mobile : +91 94408 77249 
e-mail : Abhishek_Ghosh at satyam.com 
Web : www.satyam.com 

 

************************************************************************** 
This email (including any attachments) is intended for the sole use of the
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
distribution or forwarding of any or all of the contents in this message is
STRICTLY PROHIBITED. If you are not the intended recipient, please contact
the sender by email and delete all copies; your cooperation in this regard
is appreciated.
**************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.LaTech.edu/pipermail/javascript/attachments/20050307/2af58136/a
ttachment-0001.html

------------------------------

Message: 2
Date: Mon, 7 Mar 2005 15:37:32 +0100
From: Peter-Paul Koch <pp.koch at gmail.com>
Subject: Re: [Javascript] Finding file size using java script
To: "[JavaScript List]" <javascript at latech.edu>
Message-ID: <21e4a128050307063740a5d0c at mail.gmail.com>
Content-Type: text/plain; charset=US-ASCII

>             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/
------------------------------------------------------------------


------------------------------

Message: 3
Date: Mon, 07 Mar 2005 14:35:16 +0000
From: "Richard Lewis" <richardlewis at fastmail.co.uk>
Subject: Re: [Javascript] Finding file size using java script
To: "[JavaScript List]" <javascript at LaTech.edu>
Message-ID: <1110206116.7837.216734042 at webmail.messagingengine.com>
Content-Type: text/plain; charset="ISO-8859-1"

On Mon, 7 Mar 2005 18:50:03 +0530 , "Abhishek_Ghosh"
<Abhishek_Ghosh at satyam.com> said:
> 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. To do this I cannot
use ActiveX objects as the business requirements strictly restricts use of
ActiveX >Objects. The other option is to use the following code :

>       var fileObj = document.fileSizeChecker.fileUpload.value;
>       var myFile = new File(document.fileSizeChecker.fileUpload.value);
>      myFile.open("r");
>      alert('myFile length: ' + myFile.getLength());

 >           Using the above code produces the following javascript error
"'File' is undefined". Please suggest how to bail out of this error or an
alternate method of achieving the >purpose.

File is undefined because there is not a File class in standard
JavaScript (yet, see http://www.mozilla.org/js/js-file-object.html).
Also, I don't think that 'document' has such a property as
fileSizeChecker either.

And there isn't really a way that your browser can be given permission
to fiddle around with local files. What you can do is use the 'accept'
attribute of the 'input type="file"' tag to restrict the MIME types of
files which can be uploaded but thats about it.

Cheers,
Richard




------------------------------

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


End of Javascript Digest, Vol 25, Issue 5
*****************************************
************************************************************************** 
This email (including any attachments) is intended for the sole use of the
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
distribution or forwarding of any or all of the contents in this message is
STRICTLY PROHIBITED. If you are not the intended recipient, please contact
the sender by email and delete all copies; your cooperation in this regard
is appreciated.
**************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050308/b5e1a2f1/attachment.htm>


More information about the Javascript mailing list