How to know how many Bytes have file through Javascript Arraybuffer?

Asked

Viewed 41 times

0

I’m with a file upload application, and I need to know how to identify how many bytes my file has, that’s why I’m using Arraybuffer, I know there are other ways to measure the file size, but I’d really like to use Arraybuffer, that was my attempt.

inserir a descrição da imagem aqui

I don’t know if I’m doing it right, and the right way would be another, I need to know the right way and I accept suggestions, here’s the code snippet.

if (x != "undefined"){//uint8array, arraybuffer
                await jsZipInstance.file(x).async("arraybuffer").then(function (data) {
                    var view = new Int8Array(data);
                    console.log(view.length);
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/length

  • Read the document below for examples: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array

No answers

Browser other questions tagged

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