title: NodeJS base64 image encoding not quite working
body: <p>I am using <a href="https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/profilephoto_get" rel="nofollow noreferrer">API</a> to get user's profile photo from O365 cloud. Based on the doc it says response contains 
  *The binary data of the requested photo. *</p>
  
  <p>I would like to use this image to be displayed by Data URI format. Ex:- </p>
  
  <p>"data:image/png;base64,iVBORw0KGgoAAA
  ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
  //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU
  5ErkJggg=="</p>
  
  <p>where everything after data:image/png;base64,.... is image data in Base64.</p>
  
  <p>I unable to get Base64 encoding working for the image data I am getting from API. Not sure if I am consuming raw binary img data correctly and converting it correctly to Base64.</p>
  
  <p>To verify: 
  I upload my URI data here to online editor &amp; it never parses my data/image. Instead if I upload an image <a href="http://www.dailycoding.com/Utils/Converter/ImageToBase64.aspx" rel="nofollow noreferrer">here</a> &amp; to get Base64 data then upload URI in 1st editor it does display correctly. So I am guessing by Base64 conversation isn't correct.</p>
  
  <p><strong>CODE in nodejs:-</strong></p>
  
  <pre><code>let base64ImgTry1 = Buffer.from('binary-data-from-api').toString('base64')
  
  //OR
  
  var base64ImgTry2 = new Buffer('binary-data-from-api','binary').toString('base64');
  
  let imgURI_1 = 'data:image/png;base64,' +base64ImgTry1
  let imgURI_2 = 'data:image/png;base64,' +base64ImgTry1
  </code></pre>
  
  <p>none of these imgURI_1 , imgURI_2 works. Not sure if I am going wrong consuming binary-data-from-api.</p>
  
  <p>I also tried this NPM library <a href="https://www.npmjs.com/package/image-data-uri" rel="nofollow noreferrer">https://www.npmjs.com/package/image-data-uri</a></p>
  
  <p>in which i used this method -> encode(data, mediaType) where data was direct response from API. </p>
  
  <p><a href="https://www.site24x7.com/tools/datauri-to-image.html" rel="nofollow noreferrer">https://www.site24x7.com/tools/datauri-to-image.html</a></p>