-1

I get a buffer from the server and create a new blob. For this new blob I create an Object URL, but the image is always displayed incorrectly.

This is the buffer im getting from the server: Buffer

This is how i am creating the object url for the blob: Creating object url from blob

And the result is this: Final image

Also there are no errors in the console.

  • 1
    Welcome to SO! Please put relevant code as text in the question not as images. See [Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). Also provide enough data to create a runnable [mcve] that demonstrates the issue and allows us to test the problem – charlietfl May 25 '20 at 21:55

1 Answers1

0

Try converting your byte array to an Uint8Array and see if it works

var arrayBufferView = new Uint8Array(artifactEntityObject.thumbnail.data);
var blob = new Blob( [arrayBufferView], { type: "image/jpeg" } );
var imgSource = URL.createObjectURL( blob );
Jeril Sebastian
  • 793
  • 7
  • 10
  • This works without problems, thank you very much! Could you please explain what the difference is between the buffer itself and the UInt8 array, both look the same to me in the dev tool – XIIINITRATE May 26 '20 at 06:29
  • Actually I'm not 100% sure. My guess is, and as per the documentation, the Blob constructor expects an ArrayBuffer or a Typed Array and doesn't know how to handle a array of javascript integers - https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob – Jeril Sebastian May 26 '20 at 09:22
  • Ahhh i understand, anyway, thank you very much for the solution! – XIIINITRATE May 26 '20 at 10:14