Get File Size in Bytes in Java Script

5

I'm validating the attached file size on my page before upload using the following code:

var tamanhoArquivo = parseInt(document.getElementById("documento").files[0].size);
        if(tamanhoArquivo > 2097152){ //MAX_FILE_SIZE = 2097152 Bytes
            alert("TAMANHO DO ARQUIVO EXCEDE O PERMITIDO (2MB)!");
            return false;
        }

This validation is working perfectly in all browsers, except in version 8 of IE, where it says "Can not get '0' property of undefined or null reference."

Any suggestions for size validation also in IE 8?

    
asked by anonymous 26.11.2014 / 15:09

1 answer

3

Internet Explorer 8 does not support Multiple Files. Only IE 10 onwards accepts. Documentation . So this is giving error when trying to access the position 0 .

There is no way to get the size of the file in IE 8 or IE 9.

See the Browsers that can use File Api .

    
26.11.2014 / 16:37