0

I am trying to display image while editing imformation but could not do it. I am getting below response from server.


ÿØÿàJFIFÿÛC

%# , #&')*)-0-(0%()(ÿÛC


I want to convert this response into Base64 so that I can handle but dont know how to convert it.

Can anyone tell me how to do this?

I am trying to do this but does not work..

response => {
console.log('Media',response)
let base64Data: string;
let reader = new FileReader();
reader.readAsDataURL(response);
reader.onloadend = () => {
  base64Data = reader.result;
  this.previewURL = this.sanitizer.bypassSecurityTrustUrl(base64Data);

};

Radiant
  • 360
  • 3
  • 26
  • 1
    Possible duplicate of [How to convert image into base64 string using javascript](https://stackoverflow.com/questions/6150289/how-to-convert-image-into-base64-string-using-javascript) – Lazar Ljubenović Dec 16 '17 at 11:30
  • @zgue..I am trying to do this but i dont know whether it is right or wrong.. response => { console.log('Media',response) let base64Data: string; let reader = new FileReader(); reader.readAsDataURL(response); reader.onloadend = () => { base64Data = reader.result; this.previewURL = this.sanitizer.bypassSecurityTrustUrl(base64Data); }; – Radiant Dec 16 '17 at 11:31
  • @LazarLjubenović i have gone through but did not get anything from it.. I am quite new to angular – Radiant Dec 16 '17 at 11:36
  • Using base64 has nothing to do with Angular. – Lazar Ljubenović Dec 16 '17 at 11:37
  • @LazarLjubenović okay..my bad.. – Radiant Dec 16 '17 at 11:38
  • I think it does not have anything in Angular and you got to find the possible way to do such thing using JavaScript – Mohammad Kermani Dec 16 '17 at 11:52

1 Answers1

1

You seem to be doing the right thing in the code you posted. May be the data you are getting from the server is corrupted.

For assistance you can check the sample working fiddle here that I created for you.

You can replace the base64Data with your own data in the fiddle and try to verify it.

Sandip Ghosh
  • 719
  • 7
  • 13