'Array getting converted to ArrayBuffer and giving different behaviour for Blob creation

enter image description here

This is the result object returned for saving an image file in mongodb using mongoose

Case 1

The result.img.data object has a String attribute type and an Array attribute data and that is exactly what I get on the client side if I io.emit(event, result) using socket.io

Case 2

But if I io.emit(event, result.img) then on the client side the object img.data becomes an ArrayBuffer

Why is this happening?

In Case 1 if I create a Blob using new Blob(new Uint8Array(result.img.data.data)) I get a different Blob object and the image file is unviewable

But in Case 2 if I create a Blob using new Blob([img.data]) then a different Blob object is created and the file is viewable

Why is this behaviour happening?

How can I create a viewable image Blob with the Array instead of the ArrayBuffer?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source