Last active
October 16, 2015 09:16
-
-
Save frentsel/0cbf5eccc0a79d8659e2 to your computer and use it in GitHub Desktop.
FileReader.js
This file contains hidden or 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
<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