Posted By

devnull69 on 07/12/11


Tagged

image XMLHttpRequest base64 btoa x-user-defined


Versions (?)

Load external binary data as data url


 / Published in: JavaScript
 

  1. var xmlhttp = new XMLHttpRequest();
  2. xmlhttp.open("GET",url,false);
  3. xmlhttp.overrideMimeType('text/plain; charset=x-user-defined');
  4. xmlhttp.send();
  5. var data = '';
  6. for ( var i = 0; i < xmlhttp.responseText.length; i++ ) data += String.fromCharCode( ( xmlhttp.responseText[ i ].charCodeAt(0) & 0xff ) );
  7. // Convert raw data to base64
  8. data = btoa( data );
  9. var base64src='data:image/jpg;base64,'+data; // change the MIME type according to content

Report this snippet  

You need to login to post a comment.