choose the picture locally and upload it to the server through ajax. Do not want to use the form form, use the fileReader of h5 to report an error, how to solve
converted code
convertToBase64() {
let fileReader = new FileReader()
//2m
const AllowImgFileSize = 2100000
let imgUrlBase64;
imgUrlBase64 = fileReader.readAsDataURL("https://img.alicdn.com/bao/uploaded/TB1qimQIpXXXXXbXFXXSutbFXXX.jpg")
fileReader.onloadend = function() {
if (AllowImgFileSize != 0 && AllowImgFileSize < fileReader.result.length) {
alert( "2M")
return
}else{
console.log(imgUrlBase64)
//
console.log(fileReader.result);
}
}
}
now it is dead to pass an online image address, which is actually the value obtained by input (type=file)
.
I really don"t know how to solve it. I use fileReader for the first time.
this is the simplest. Is there any other simple and feasible way? Using the react framework