Last active
April 8, 2016 04:06
-
-
Save yasirtaher/1d00a7d102c4baf31c52d351bc136983 to your computer and use it in GitHub Desktop.
This file contains 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
//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