我试图通过HTTP Post发送图像。 我试过这段代码,但图片没有
var image = document.createElement('img');
image.src='images/qrcode_teste.png';
image.id=event.filename;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 1200;//image.width;
canvas.height = 1200;//image.height;
ctx.drawImage(image, 0, 0);
var dataUrl = canvas.toDataURL('image/png');
var blob = dataUriToBlob(dataUrl);
document.body.appendChild(canvas);
// submit as a multipart form, along with any other data
var form = new FormData();
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://zxing.org/w/decode', true); // plug-in desired URL
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
alert('Success: ' + xhr.responseText);
document.body.removeChild(document.getElementById("overlay"));
$("body").toggleClass("dialogIsOpen");
} else {
document.body.removeChild(document.getElementById("overlay"));
$("body").toggleClass("dialogIsOpen");
alert('Error submitting image: ' + xhr.status);
}
}
};
form.append('f', blob);
xhr.send(form);`