title: Convert Binary form to base64 string in javascript
body: <p>I am querying salesforce for some attachment data and it returns the data in binary format.</p>
  
  <p><a href="https://i.stack.imgur.com/ixKnz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ixKnz.png" alt="enter image description here"></a></p>
  
  <p>I have tried to convert the same to base64, but I have been quite unsuccessful so far. I have tried the <code>btoa()</code> method but it returns <code>the The string to be encoded contains characters outside of the Latin1 range.</code> error.</p>
  
  <p>I tried to use the fileReader method i.e., <code>readAsDataURL()</code>, it returns the base64 string but unfortunately that doesn't represent the image. </p>
  
  <p>COuld you please help me out as to how to convert the binary form of the data to base64encoded string?</p>
  
  <p><strong>Edit</strong>
  Ultimately, I want to show the image on the webpage with the data I am getting which I am unable to do</p>