简体   繁体   English

将本地图像转换为base64 javascript

[英]Convert local image to base64 javascript

As Convert local image to base64 string in Javascript . 将本地图像转换为Javascript中的base64字符串 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: 我正在android设备和图像路径中进行测试:

/storage/extSdCard/1.jpg /storage/extSdCard/1.jpg

How can i convert image from local mobile device to base64? 如何将图像从本地移动设备转换为base64?

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); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM