Skip to content

Instantly share code, notes, and snippets.

@tarqd
Created November 7, 2012 19:06
Show Gist options
  • Save tarqd/4033671 to your computer and use it in GitHub Desktop.
Save tarqd/4033671 to your computer and use it in GitHub Desktop.
function sendBlob(blob) {
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('post-data', 'goeshere');
fd.append('foo', 'bar');
// use the right name for the file (the name element of the form ussually)
fd.append('file', blob);
xhr.open('POST', 'http://YOUR.DOMAIN.HERE/posturl.php', true);
xhr.send(fd);
}
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
var context = canvas.getContext();
var imageObj = new Image();
imageObj.onload = function () {
context.drawImage(this, 0, 0);
context.toBlob(sendBlob);
};
imageObj.src = "http://theimage.com/bla.jpg";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment