Skip to content

Instantly share code, notes, and snippets.

@auggernaut
Created May 14, 2013 01:36
Show Gist options
  • Save auggernaut/5572985 to your computer and use it in GitHub Desktop.
Save auggernaut/5572985 to your computer and use it in GitHub Desktop.
Read an array of image files with FileReader
//ADD IMAGE
//http://www.html5rocks.com/en/tutorials/file/dndfiles/
var files = $('input[id = file]')[0].files; // FileList object
var fileName = $('#pretty-input').val();
// Loop through the FileList
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
fileName = theFile.name;
return function (e) {
Gratzi.Store.addImage(e.target.result, theFile.name, function (path) {
console.log("Image Uploaded: " + path);
});
};
})(f);
reader.readAsArrayBuffer(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment