Get File Size in Bytes in Java Script

Asked

Viewed 4,182 times

5

I am validating the size of the attached file on my page before uploading 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 for version 8 of IE, where it says "Unable to get the '0' property of indefinite or null reference".

Any suggestions for size validation also in IE 8?

1 answer

3


Internet Explorer 8 does not support Multiple Files. Only IE 10 on accepts. Documentation. That is why you are giving error when trying to access the position 0.

No way to grab, using javascript only, the size of the file in IE 8 or IE 9.

See the Browsers that can use File Api.

  • Is there any other way to validate still in front-end in IE 8 and 9 ?

  • 1

    I came here to answer this question, and I couldn’t find it. What I saw were people using java applets to do this treatment, however it was not very clear so I left it aside.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.