Angular 2 base64 image how to use?

0

I have an "ERR_INVALID_URL" error and it does not load the image. Does anyone know how to solve it? My html and Ts are like this.

//Aqui está vindo a url do servidor 
    let a = value.params["dataBuffer"]; 

    //Aqui estou convertendo o base64 passando para 
      variavel imagePath q é do tipo any;
    this.imagemPath = this.sanitizer.bypassSecurityTrustResourceUrl("data:image/png;base64, a");



   ----- No meu arquivo HTML -----------
    <img [src]="imagemPath">
    
asked by anonymous 02.10.2018 / 21:25

1 answer

0

Instead of using the sanitizer.bypassSecurityTrustResourceUrl feature you can place the base64 code directly into the src attribute:

this.imagemPath = 'data:image/png;base64, ${a}';

Make sure that during your conversion to base64 the return string already comes with the string ' data:image/png;base64, ', if you do not need the above concatenation

    
03.10.2018 / 19:04