In angle 2, how to obtain / regenerate an image stored in database? [closed]

-1

I have a backend made in java where I persist images in a psql database using hibernate, the images I am saving in with the data type Byte []. On the other hand I am developing a client application in angular 2, with this client application I made the connection with the backend and consumed via rest the object with its image property. The question is, how do I regenerate the image of the object consumed from the server (property in bytes) or some idea of how to work with the treatment of images consumed from the server and regenerated in the client? Thank you very much.

    
asked by Nicolas Bloj 23.09.2017 в 00:22
source

1 answer

1
  

Order and store the bytes that represent your image

const bytes = [];
  

Convert the bytes to a base64 string

const base64String = btoa(String.fromCharCode(...new Uint8Array(bytes)));
  

Prepare the image data source

const source = 'data:image/png;base64,${base64String}';
  

Give it to the image

<img [src]="source"/>
    
answered by 23.09.2017 в 00:41