I am fetching an image via a http request which returns a blob and i want to assign the blob returned to an image src.
http request:
const options = {
headers,
responseType: 'blob' as 'json'
};
return this.httpClient.get(url, options)
component.ts
async ngOnInit() {
this.frontImageSrc = getImage()
}
async getImage() {
const image = await this.service.imageRequest(id, "front", token).toPromise();
var imageUrl = URL.createObjectURL(image)
return imageUrl
}
component.html
<img src={{frontImageSrc}} alt="image"/>
The image src does not get assigned and in the console i can see the following.
blob:http://localhost:4200/f846a3aa-8cd3-4876-8dd3-972c9469feb2 14:00:00.664 unsafe:blob:http://localhost:4200/f846a3aa-8cd3-4876-8dd3-972c9469feb2:1 GET unsafe:blob:http://localhost:4200/f846a3aa-8cd3-4876-8dd3-972c9469feb2 net::ERR_UNKNOWN_URL_SCHEME
SanitzerandbypassSecurityto see if it works. Also it's better to use property binding instead of binding literal like[src]="frontImageSrc". Besides that don't forget to revoke your blob url inngOnDestroy. If this works I can post it as an answer.