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.

Mukund
  • 21
  • 5

1 Answers1

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.

santosh singh
  • 27,666
  • 26
  • 83
  • 129
  • 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 Jan 18 '18 at 05:32
  • @Mukund: this https://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte link might help you – santosh singh Jan 18 '18 at 05:45