Created
January 3, 2020 01:39
-
-
Save hadrysmateusz/21c38ff0d46273b48f00db76ee0a179c to your computer and use it in GitHub Desktop.
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
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
const inputElement = document.getElementById("inputElement") | |
inputElement.onchange = (e) => { | |
const file = inputElement.files[0] | |
if (!file) return | |
const reader = new FileReader() | |
reader.onload = (e) => { | |
// e.target points to the reader | |
const textContent = e.target.result | |
console.log(`The content of ${file.name} is ${textContent}`) | |
} | |
reader.onerror = (e) => { | |
const error = e.target.error | |
console.error(`Error occured while reading ${file.name}`, error) | |
} | |
reader.readAsText(file) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment