Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Created February 28, 2020 19:09
Embed
What would you like to do?
document.getElementById('button').addEventListener('click', function() {
var files = document.getElementById('file').files;
if (files.length > 0) {
getBase64(files[0]);
}
});
function getBase64(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
console.log(reader.result);
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment