I have a simple cuestion. I have the following service in angular 4 app.
getProviderPhoto(id:string){
return this.http.get(this.apiUrl+"/"+id+"/images", {responseType: "blob"});
}
I need to convert this Blob response to Image file to use the following method:
createImageFromBlob(image: Blob) {
let reader = new FileReader();
this.photo = new File([image],"foto.png",{ type: 'image/png' });
reader.readAsDataURL(this.photo);
reader.onload = (event: any) => {
this.image=event.target.result;
console.log(this.image);
}
}
console.log
data:image/png;base64,ImlWQk9Sd.....
To use the downloaded image to show it in my html:
<div class="profile-image center" [ngStyle]="{ 'background-image': 'url(' + image + ')'}"></div>
On the other hand, if I do this, it works perfectly:
this.image="http://localhost:8083/v1/providers/"+this.id+"/images";
How can I get the same result but using Angular HttpClient.Get?
I've tried a thousand ways but I can not get it to work? Really it's quite hard to fathom. See this and thisdata:image/png;base64,?this.photo = new File([image],"photo.png",{ type: 'image/png' });ofcreateImageFromBlobmethod it start with data:application/json;base64,DomSanitizerpreventing XSS when trying to set this specific background-image style property. You may need to usebypassSecurityTrustStyle(). See this answer