Skip to content

Instantly share code, notes, and snippets.

@hadrysmateusz
Created January 3, 2020 01:39
Show Gist options
  • Save hadrysmateusz/21c38ff0d46273b48f00db76ee0a179c to your computer and use it in GitHub Desktop.
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
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