Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FileReader - AngularJS service wrapper for window.FileReader
app.factory('FileReader', function($q, $window) {
if (!$window.FileReader) {
throw new Error('Browser does not support FileReader');
}
function readAsDataUrl(file) {
var deferred = $q.defer(),
reader = new $window.FileReader();
reader.onload = function() {
deferred.resolve(reader.result);
};
reader.onerror = function() {
deferred.reject(reader.error);
};
reader.readAsDataURL(file);
return deferred.promise;
}
return {
readAsDataUrl: readAsDataUrl
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.