0

As Convert local image to base64 string in Javascript . I know how to use it, but it work if image file include in project, not work with another folder. I'm test in android device and my image path like:

/storage/extSdCard/1.jpg

How can i convert image from local mobile device to base64?

Community
  • 1
  • 1
Lucy Vo
  • 5
  • 1
  • 4

1 Answers1

3
function readImage(url, callback) {   
    var request = new
    XMLHttpRequest();   request.onload = function() {
       var file = new FileReader();
       file.onloadend = function() {
          callback(file.result);
       }
       file.readAsDataURL(request.response);   };   
       request.open('GET', url);   
       request.responseType = 'blob';              
       request.send(); 
}

and call function

readImage('[path image] ',  function(base64) {  console.info(base64); 
});
Pr3ds
  • 393
  • 3
  • 14