Skip to content

Instantly share code, notes, and snippets.

@amundo
Forked from jollytoad/gist:4201905
Created November 20, 2013 21:56
Show Gist options
  • Save amundo/7571798 to your computer and use it in GitHub Desktop.
Save amundo/7571798 to your computer and use it in GitHub Desktop.
function readFile(file) {
var reader = new FileReader();
var deferred = $.Deferred();
reader.onload = function(event) {
deferred.resolve(event.target.result);
};
reader.onerror = function() {
deferred.reject(this);
};
if (/^image/.test(file.type)) {
reader.readAsDataURL(file);
} else {
reader.readAsText(file);
}
return deferred.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment