0

I want to show a image in my code. The image has been saved in text format in my database. I convert the string of image in image with the following line code:

 <img [src]="'data:image/png;base64,'+zona?.fotografia">

I succeed to show the image in the page, but in the console there are the following errors:

WARNING: sanitizing unsafe URL value data:image/png;base64
GET unsafe:data:image/png;base64, net::ERR_UNKNOWN_URL_SCHEME

If i have seen the possible solution for the warning, i didn't understand the other error..

1 Answer 1

1

You need to ensure your application that this is an safe url. So you can do it via DomSanitizer service. Inject it into your component and use bypassSecurityTrustUrl method.

this.fotografia= this.sanitizer.bypassSecurityTrustUrl(`data:image/png;base64,${this.zona?.fotografia}`)

and use it in the <img [src]="fotografia">

Sign up to request clarification or add additional context in comments.

1 Comment

I have followed your suggestion and there aren't error, but there is a new error: GET localhost:4200/null 404 (Not Found)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.