Created
April 25, 2019 19:26
-
-
Save evertonstrack/995da7facaf19e6c5e565d42874041e0 to your computer and use it in GitHub Desktop.
readTxtFile.js
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
function readTxtFile(event) { | |
return new Promise((resolve, reject) => { | |
const file = event.target.files[0]; | |
const reader = new FileReader(); | |
reader.onload = () => resolve(reader.result); | |
reader.readAsText(file); | |
}); | |
} | |
document.getElementById('files').addEventListener('change', function(e){ | |
readTxtFile(e) | |
.then(res => console.log('then', res)) | |
.catch(err => console.log('err', err)); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment