1
I have the code below where I need to display an image coming from the database, the image is coming here as byte how to display this image on the screen?
<!-- Listar As Bebidas Alcoólicas -->
<div class="card-columns" *ngIf="bebidasAlcoolicas != null">
<div class="card" *ngFor="let bebidaAlcoolica of bebidasAlcoolicas">
<button type="button" class="btn btn-danger" (click)="incluirCarrinhoBebidaAlcoolica(bebidaAlcoolica)">
<img class="card-img-top" src="bebidaAlcoolica.imagemBebidaAlcoolica" alt="Card image cap">
</button>
<div class="card-body">
<h5 class="card-title text-primary font-weight-bold">{{bebidaAlcoolica.nomeBebidaAlcoolica}}</h5>
<p class="card-text text-danger">{{bebidaAlcoolica.valorBebidaAlcoolica | currency:'BRL':true}}</p>
</div>
</div>
</div>
Attempt 2:
request-piece.create-Component.ts
loadImagem(encryptedImage) {
this.imageData = 'data:image/png;base64,' + encryptedImage;
this.sanitizedImageData = this.sanitizer.bypassSecurityTrustUrl(this.imageData);
console.log(this.sanitizedImageData);
}
standalone.create-Component.html
<!-- Listar As Bebidas Alcoólicas -->
<div class="card-columns" *ngIf="bebidasAlcoolicas != null">
<div class="card" *ngFor="let bebidaAlcoolica of bebidasAlcoolicas">
<button type="button" class="btn btn-danger" (click)="incluirCarrinhoBebidaAlcoolica(bebidaAlcoolica)">
<img class="card-img-top" [src]='sanitizedImageData' *ngIf="loadImagem(bebidaAlcoolica.imagemBebidaAlcoolica)" alt="Card image cap">
</button>
<div class="card-body">
<h5 class="card-title text-primary font-weight-bold">{{bebidaAlcoolica.nomeBebidaAlcoolica}}</h5>
<p class="card-text text-danger">{{bebidaAlcoolica.valorBebidaAlcoolica | currency:'BRL':true}}</p>
</div>
</div>
</div>
What is the language of your backend?
– vinibrsl
Good afternoon, my Backend is Java.
– Ederson Coelho
Angular, to render the image, requires it to be in Base64
– vinibrsl
It is not byte[] it arrives as a string in JSON.
– Ederson Coelho
i open this site: https://codebeautify.org/base64-to-image-converter put the string and Gero the image that is saved in the database.
– Ederson Coelho