2

I'm getting the below data which is a jpeg image in response body. Below is a screen shot of the response.

Screenshot of response

Screenshot of response body

When i do type of res._body, it is a string. How can i convert it base64 string so I can render the image in browser, or is there an easier/another way to solve this. This is a part of angular app I'm building.

1
  • <img src="path_to_server"> might do. Commented Jan 18, 2018 at 5:47

1 Answer 1

2

Try following code snippet

 convertToBase64 (binaryString) { this.base64textString= btoa(binaryString); console.log(base64textString); } 

Update

If you have UTF8 check out following thread

Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

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

2 Comments

this didn't work, I'm getting "Error DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
@Mukund: this stackoverflow.com/questions/23223718/… link might help you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.