Skip to content

Instantly share code, notes, and snippets.

@frentsel
Last active October 16, 2015 09:16
Show Gist options
  • Save frentsel/0cbf5eccc0a79d8659e2 to your computer and use it in GitHub Desktop.
Save frentsel/0cbf5eccc0a79d8659e2 to your computer and use it in GitHub Desktop.
FileReader.js
<form enctype="multipart/form-data">
<input type="file" name="files" id="files" multiple onchange="File.set(this)">
</form>
var File = (function(){
var files = [],
set = function(obj){
for(var i in obj.files)
{
if(typeof obj.files[i] === 'object')
{
(function (file) {
var reader = new FileReader();
reader.onload = function (e) {
files.push({
name: [file.name],
src: e.target.result
});
};
reader.readAsDataURL(file);
})(obj.files[i]);
}
}
},
get = function(){
return files;
};
return {
get: get,
set: set
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment