作者:q40796672 | 来源:互联网 | 2023-07-03 15:01
functiongetBase64Image(img){varreadImgnewFileReader();readImg.readAsDataURL(img);
function getBase64Image(img) {
var readImg = new FileReader();
readImg.readAsDataURL(img);
readImg.Onload= function (readEvent){
var base64="";
if(img.size>524288){
var tmpimg = new Image;
var quality = 0.9;
var cv = document.createElement("canvas");
var drawer = cv.getContext("2d");
tmpimg.src = this.result;
cv.image/jpeg", quality);
//console.log(tmpsrc);
base64 = tmpsrc;
//alert(1);
}else{
base64 = readEvent.target.result;
//alert(2);
}
//.substr(23); // base64字符串
//var base64 = readEvent.target.result;
$("#image").attr("src", base64);
$.ajax({
type:"post",
url:"../sendBase.ilf",
data:{
"bases":base64,
"name":img.name,
"uuid":uuid
},
dataType:"json",
async:false,
success:function(data){
if(data == "1"){
console.log("Upload Success!");
success=success+1;
//alert(success+"--"+length);
if(success==length){
length=0;
success=0;
alert("Upload Success!");
}
allFiles=null;
imgFile=null;
$("#image").empty();
}else{
console.log("Upload failure!");
alert("Upload failure!");
allFiles=null;
imgFile=null;
$("#image").empty();
}
}
});
};
}