Skip to content

Instantly share code, notes, and snippets.

@KensakuKOMATSU
Created July 29, 2013 00:27
Show Gist options
  • Save KensakuKOMATSU/6101434 to your computer and use it in GitHub Desktop.
Save KensakuKOMATSU/6101434 to your computer and use it in GitHub Desktop.
(File System APIの)imgファイルをxhr2でサーバーにuploadするスクリプト
$("<canvas>").appendTo("body");
var canvas = $("canvas")[0]
, ctx = canvas.getContext('2d')
canvas.width = 640, canvas.height = 480;
for(var i = 0, l = ent.length; i < l; i++) {
var imgURL = ent[i];
var img = new Image();
img.src = imgURL;
img.onload = function(e){
console.log(this.src)
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL();
console.log(dataURL);
var name_ = this.src.split("/").slice(-1)[0]
$.post('http://localhost:3000/upload', {name:name_, data: dataURL})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment