I am trying to display avatar which is fetched from server which takes avatar from MySql db. I am receiving image from server as arrayBuffer which is saved in state.
And server side:
CodePudding user response:
You can view with base64 encode;
function toBase64(arr) {
return btoa(arr.reduce((data, byte) => data String.fromCharCode(byte), ''));
}
How to use?
<img src={`data:image/png;base64,${toBase64(response.data.avatar)}`} />
CodePudding user response:
Check out this answer. This will help you convert the binary data to an actual image.