Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Created February 28, 2020 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zuzannamj/35953072b99a35434289f65876e55bed to your computer and use it in GitHub Desktop.
Save zuzannamj/35953072b99a35434289f65876e55bed to your computer and use it in GitHub Desktop.
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