title: Convert Image Stream (JFIF - JPEG) format to DataURI using Javascript
body: <p>I have tried to search an answer for this all over. It seems pretty straightforward, but my lack of knowledge of Javascript (Been coding in Java all along) combined with Image stream conversion on Javascript side makes this hard.</p>
  
  <p>I make a REST request url - <code>https://&lt;&lt;host&gt;:port/getPicture</code> and it produces a <code>image/jpeg</code> streaming response.</p>
  
  <p>Once I fire the URL in Chrome browser - the image is rendered correctly. It is also rendered in my angularJS app - via ng-src tag e.g. <code>&lt;img ng-src="url"/&gt;</code></p>
  
  <p>However, when I try to set the raw data to ng-src tag, it does not seem to work. On further reading I understood that ng-src does not accept raw image data, but needs to be converted to a base64String to be used as a DataURI. I tried to look up articles everywhere to convert raw image data (JFIF format) to DataURI and was unsuccessful.</p>
  
  <p>Shown below is response raw data looks (I open it in a browser, it renders perfectly).</p>
  
  <p>Questions -
  1. What format is the raw data? Binary Stream or Byte Array? Or what is it?
  2. How do I convert this in to a DataURI in Javascript so that it can be linked to my ng-src tag?</p>
  
  <p>Request you to help me on this one. Seems so easy, but has taken me a week now and driving me nuts!!</p>
  
  <pre><code>����JFIF``��C       
  
   $.' ",#(7),01444'9=82&lt;.342��C          
  
  2!!22222222222222222222222222222222222222222222222222���|"��    
  ���}!1AQa"q2���#B��R��$3br� 
  %&amp;'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������    
  ���w!1AQaq"2�B����  #3R�br�
  $4�%�&amp;'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?�4���)����4�㊎D,&gt;W�}jLsIބ�Y~{鑻a��6�ҙb�'��I�Fj�+��K�R
  �dhr=���4�������+R~S���Zq�&gt;�g �5Vղ_��[�y��(,�����Ґ2�$?Z@(��K��I�|Ro��G#қ��K�Ґ��pM7|7w��I���Q@��)��J��jIeo��?�篵Z�����9��8�a����[W%�r��F2E4Es�e��/������]��i�92�Pf���݃yo��O��n���9f�]�;W�=zRt��綃ނ*}Z{ׂ�P!�̤�YEt�s�!���s���zR�EQdP�]\��b�@̫����Q������d��k��t�&amp;�Nk�L��@f�&amp;�&gt;Ê�u�����������`���-�s�/    ���ʪF�p)�f�c�(aLd?p�I�I��7Rr=h��i����2=�2�4���P��'�3擨*����%ߖ�*]��`Q�ڌ�&amp;G�+��5䈹E��Mu2F����E���jϔp�����_�qp����^�V������^�ː���̬b�'l�E/��'漛��
  </code></pre>