【问题标题】:Convert local image to base64 javascript将本地图像转换为 base64 javascript
【发布时间】:2017-02-10 18:53:18
【问题描述】:

作为Convert local image to base64 string in Javascript 。我知道如何使用它,但如果图像文件包含在项目中,它就可以工作,而不是与另一个文件夹一起工作。我在 android 设备和我的图像路径中进行测试,例如:

/storage/extSdCard/1.jpg

如何将图像从本地移动设备转换为 base64?

【问题讨论】:

    标签: javascript android base64


    【解决方案1】:
    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(); 
    }
    

    调用函数

    readImage('[path image] ',  function(base64) {  console.info(base64); 
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 2015-12-09
      • 2020-06-01
      • 2014-02-09
      • 2017-06-06
      • 1970-01-01
      相关资源
      最近更新 更多