Skip to content

Instantly share code, notes, and snippets.

@claraj
Created October 8, 2019 20:32
Show Gist options
  • Save claraj/e2d937bc81efa109f2e9891cffb5501f to your computer and use it in GitHub Desktop.
Save claraj/e2d937bc81efa109f2e9891cffb5501f to your computer and use it in GitHub Desktop.
<img id="uploaded-image">
<input id="image-input" type="file">
<button id="upload">Click to upload</button>
<script>
let img = document.querySelector("#uploaded-image")
let input = document.querySelector("#image-input")
let button = document.querySelector('#upload')
let reader = new FileReader()
reader.addEventListener('load', function() {
img.src = reader.result
}, false)
button.addEventListener('click', function() {
console.log(input.files)
let filename = input.files[0]
// img.attributes.src = filename
reader.readAsDataURL(filename)
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment