Jan 13, 2012, 9:30 AM
How to validate file size before upload at client side ( Javascript ) ?
Hi all,
I'm using control "FileUploadField" to upload file to the server. The file to be upload is required to not exceed maximum size.
Therefore, I wonder how can I check the size of the file before uploading , by Javascript ?
Thanks for help.
My code :
+ FileUploadField :
I'm using control "FileUploadField" to upload file to the server. The file to be upload is required to not exceed maximum size.
Therefore, I wonder how can I check the size of the file before uploading , by Javascript ?
Thanks for help.
My code :
+ FileUploadField :
<ext:FileUploadField ID="FileUploadFieldAttachment" runat="server" Width="212" />
+ Button Action : <ext:Button ID="ButtonUpload" runat="server" Text="Upload">
<Listeners>
<Click Fn="ValidateFileSize"></Click>
</Listeners>
<DirectEvents>
<Click OnEvent="InsertNewAttachment">
</Click>
</DirectEvents>
</ext:Button>
I have used this function, but it does not work : function ValidateFileSize() {
var node = document.getElementById('ChildPage_FileUploadFieldAttachment-file');
alert(node);
if (node != null) {
alert(node.files);
if (node.files != null) {
var check = node.files[0];
alert(check);
if (check != null) {
var checkSize = check.fileSize;
alert(checkSize);
if (checkSize / 1024 > 10240) {
Ext.Msg.alert('Confirm', "Your file is too big !");
return false;
}
}
}
}
return true;
}
Last edited by fac; Jan 14, 2012 at 5:36 AM.