0

I was trying to send an image by an HTTP Post. I tried this code but the image don't goes

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);` 
dcodesmith
  • 9,590
  • 4
  • 36
  • 40
JMN
  • 21
  • 2
  • Where is your `dataUriToBlob` implementation? You've to write that part. Check this: http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata – sanjeev mk Dec 27 '13 at 11:20
  • sorry i have that on my code i had forget of putting that on my post, my real problem its not on the transfer of the image, the problems is on the convertion of image to canvas because in element i append an everything its ok but appending the screen apears with nothing. But thanks for the help – JMN Dec 27 '13 at 12:02

0 Answers0