Created
May 14, 2013 01:36
-
-
Save auggernaut/5572985 to your computer and use it in GitHub Desktop.
Read an array of image files with FileReader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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