本文介绍了如何基于64位在同一文件中的两个图像中进行编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我有两个表单字段,在此我想将base 64编码从图像转换,然后我想将JSON格式传递给下一个URL,我尝试过这样,但是我没有得到,有时我我正在获取一个未提交的值(编码值)未捕获的错误property_img,我不知道该怎么做有人帮助我

Here i have two form fields , in this i want to convert the base 64 encode from image,and after that i want to pass in JSON Format to next URL, i tried like this but i am not getting ,some time i am getting one filed value (encoded value) uncaught error property_img , i don't know how to do anyone help me pls

var files = document.getElementById('floorplan_img').files;
if (files.length > 0) {
  var file = files[0];
  var reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onload = function() {
    console.log(reader.result);
    var base64 = reader.result;
    var str = base64;
    var arr = str.split(",");
    var floor_img = arr[1];
    console.log(floor_img);
  };
  reader.onerror = function(error) {
    console.log('Error: ', error);
  };

}


var files1 = document.getElementById('upload_properties').files;
if (files1.length > 0) {
  var file1 = files1[0];
  var reader1 = new FileReader();
  reader1.readAsDataURL(file1);
  reader1.onload = function() {

    var base64_img = reader1.result;
    var str_64 = base64_img;
    var arr_str = str_64.split(",");
    var property_img = arr_str[1];
    console.log(property_img);
  };
  reader1.onerror = function(error) {
    console.log('Error: ', error);
  };


}
<input type="file" id="floorplan_img">

<input type="file" id="upload_properties">

推荐答案

尝试一下:

var reader = new FileReader();
reader.onload = function(event) {
    var src= event.target.result;
    console.log(src);
};

这篇关于如何基于64位在同一文件中的两个图像中进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 03:32