Home > Mobile >  How to display image from MySQL?
How to display image from MySQL?

Time:08-17

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.

React code

States

And server side:

Server

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.

  • Related