E
E
Edgar2021-01-18 11:50:02
JavaScript
Edgar, 2021-01-18 11:50:02

The server sent an object of type 'Buffer'. How can I link it to an image?

600549bf24497065238192.png

The server sends me a response where, among other data, under the 'image' key there is an object with type: 'Buffer', it should be an image.
Under the data key is an array with numbers.

Tried to get a link.

const src = useMemo(() => {
    const imgBlob = new Blob(image?.data || [], { type: 'image/jpg' });
    return URL.createObjectURL(imgBlob);
  }, [image]);


But the link you received doesn't show anything. What can I do from the frontend? Or maybe changes are needed on the backend?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanovich, 2021-01-18
@lp1641

From the back side, you need to convert the buffer to base64, since this is done very simply and then everything should work correctly on the front end side. PS I think that it is not possible to convert buffer directly from the frontend, because buffer itself is a joke from nodejs, js in the browser knows nothing about it.
Buffer.from('your img buffer').toString('base64')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question