Created
March 23, 2021 19:06
-
-
Save nelsonfncosta/d47038a34ef8d8c4f06e8386806cfd40 to your computer and use it in GitHub Desktop.
READ FILE snippet
This file contains hidden or 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 readFile(file: File | null) { | |
const reader = new FileReader(); | |
reader.addEventListener("load", (event) => { | |
const result = event.target.result; | |
console.log(result); | |
}); | |
reader.addEventListener("progress", (event) => { | |
if (event.loaded && event.total) { | |
const percent = (event.loaded / event.total) * 100; | |
console.log(`Progress: ${Math.round(percent)}`); | |
} | |
}); | |
reader.readAsText(file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment