我通过使用JS阅读器解决了这个问题,从中读取数据URI,然后使用后xmlhttpRequest通过formdata发送它。
if (file) {
if (!file) throw null;
swal.showLoading();
const reader = new FileReader;
reader.onload = (e) => {
const fd = new FormData;
fd.append('image', e.target.result);
if (window.XMLHttpRequest) {
// code for modern browsers
var xmlhttp = new XMLHttpRequest();
} else {
// code for old IE browsers
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
// ... do something ...
};
xmlhttp.open("POST", "includes/uploadimage.php", true);
xmlhttp.send(fd);
};
reader.readAsDataURL(file)
}