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?

1 Answer 1

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); 
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.