javascriptarraybuffer

I created a new file using arrayBuffer, but it is different from the original file. How can I make a file identical to the original one?


enter image description here

uint8 is an arrayBuffer created using reader.readAsArrayBuffer from an image file. The size of this arraybuffer is 30984. The size of the original image file is also 30984.

However, if you create a new file using this uint8, the capacity also increases, and it seems that a file other than an image file is created and uploaded. Looking at the captured image below, the size of the newly created file is 69596.

Why is this different? How can I create the same file?

I am implementing a file upload by receiving a binary file. enter image description here


Solution

  • The arrayBuffer argument needs to be an entry in an array passed to new File as its first argument, as documented under bits in MDN documentation.

    Assuming uint8 is the arrayBuffer, the call would look like

    var resultFile = new File([uint8], "test.jpg");
    

    Please do not post code as images - it makes it difficult if not impossible for readers to explore the code or try it out.