原文链接:https://blog.csdn.net/hfutzhouyonghang/article/details/81394799
原文链接:https://blog.csdn.net/danby2/article/details/104529713/
// 上传图片 functionupload(image){ var imgFile=dataURLtoFile(image,"img.png");
var xhr=new XMLHttpRequest();
var fd=new FormData();
xhr.open('POST','/springStudy/user/multifiles');
fd.append("multipartFile",imgFile);
xhr.send(fd);
console.log('上传json!')
}
//将图片Base64 转成文件 functiondataURLtoFile(dataurl, filename){ console.log("转文件")
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
}