Skip to content

Instantly share code, notes, and snippets.

@yasirtaher
Last active April 8, 2016 04:06
Show Gist options
  • Save yasirtaher/1d00a7d102c4baf31c52d351bc136983 to your computer and use it in GitHub Desktop.
Save yasirtaher/1d00a7d102c4baf31c52d351bc136983 to your computer and use it in GitHub Desktop.
//convert image binary
function files_to_urls(files, callback) {
if (files.length > 0) {
var promises = [].map.call(files, function (file) {
return new Promise(function (ok, ng) {
var reader = new FileReader();
reader.onload = function (ev) {
ok(reader.result);
};
reader.onabort = function (ev) {
ok(null);
};
reader.onerror = function (ev) {
ng(reader.error);
};
reader.readAsDataURL(file);
});
});
Promise.all(promises)
.then(callback);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment