Skip to content Skip to sidebar Skip to footer

How Convert Type Data Buffer To Image In React Js

Hello, i have next the image de type buffer, this data is one image, how can I convert my buffer data into an image it shows me the following data when I make the request to the ap

Solution 1:

First, you need to convert your Buffer to base64 string

const base64String = btoa(String.fromCharCode(...newUint8Array(arrayBuffer)));

Second, you need to use your string as src attribute for img tag

<img src={`data:image/png;base64,${base64String}`} alt=""/>

I assume you are using react, so I recommend saving base64String in the component state and using it.

Post a Comment for "How Convert Type Data Buffer To Image In React Js"