Javascript FormData,iOS上带blob映像的XMLHttpRequest
我试图通过上传将Javascript FormData,iOS上带blob映像的XMLHttpRequest,javascript,php,ajax,file-upload,mobile-safari,Javascript,Php,Ajax,File Upload,Mobile Safari,我试图通过上传将contentEditable元素中粘贴的图像(blob)转换为“正确”的图像 function convertimages(article) { images = article.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { if(images[i].src.startsWith('blob:')){ formData = new FormData
contentEditable
元素中粘贴的图像(blob)转换为“正确”的图像
function convertimages(article)
{
images = article.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
if(images[i].src.startsWith('blob:')){
formData = new FormData();
fetch(images[i].src)
.then(function(response) {
return response.blob()
})
.then(function(blob) {
formData.append("image", blob );
});
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","image.php",false);
xmlhttp.send(formData);
images[i].src = xmlhttp.responseText;
}
}
}
我的代码用于获取图像并上传它们
function convertimages(article)
{
images = article.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
if(images[i].src.startsWith('blob:')){
formData = new FormData();
fetch(images[i].src)
.then(function(response) {
return response.blob()
})
.then(function(blob) {
formData.append("image", blob );
});
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","image.php",false);
xmlhttp.send(formData);
images[i].src = xmlhttp.responseText;
}
}
}
但是当检查$\u文件时,它是一个空数组。承诺..Promises
async function convertimages(article)
{
images = article.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
if(images[i].src.startsWith('blob:')){
formData = new FormData();
await fetch(images[i].src)
.then(function(response) {
return response.blob()
})
.then(function(blob) {
formData.append("image", blob );
}).then(function(){
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","image.php",false);
xmlhttp.send(formData);
images[i].src = xmlhttp.responseText;
});
}
}
}
异步函数转换图像(文章)
{
images=article.getElementsByTagName('img');
对于(var i=0;i
我第一次接触他们欢迎@beiert!您在这里提供的内容实际上没有向我们显示$\u文件
的设置位置,而且缺少的内容太多,我们无法判断出哪里出了问题。我建议您阅读并编辑您的问题,以便我们可以调试正在进行的操作。$\u文件由php运行时设置,其中包含:“通过HTTP POST方法上载到当前脚本的项目的关联数组。此数组的结构在POST方法上载部分中进行了概述。”已经完成了执行,使用一个空的formdata这种方式可以工作,但是我觉得我正在破坏整个异步/远离主线程的咒语