Hello all,

In JSP / HTML, I want to restrict the size of file being uploaded.

<input type="file" name="myfile"/>

If the user trying to upload a file size bigger than some value say 5MB, i want to give mesage to the user. I don't want to wait till the file gets uploaded to server and then validate the file size. I am looking for client side validation. Can it be done using scripting language or any other way?

I need a solution for this in Internet Explorer. I got a solution using ActiveX control:

var myFSO = new ActiveXObject("Scripting.FileSystemObject");
[I]var filepath = document.getElementById('myfile').value;
var thefile = myFSO.getFile(filepath);
var sizeInBytes = thefile.size;


But ActiveX controls are not allowed in our application. Is there any alternative way for this?

Please suggest the possible ways.. Thanks!!

Not using JavaScript. You can do this using Silverlight or Flash. If you are using .Net you could try using HTTPModules.

Thanks stbuchok. It is J2EE application. Can you please explain how do in java. Is it only Flash? I ready some articles saying Adobe Flash doesn't have features to validate file size at clinet-side. Some saying difficult to do.. http://forums.adobe.com/message/3318101?tstart=0

Also if going by Adobe flash approach, it forces IE clients to install Flash 10+ player which is not possible in our case. Could please suggest/elaborate on this..

If this is a J2EE app, can't you use an applet?