Created
August 22, 2022 03:59
-
-
Save amrikarisma/96eb406bca39385bc42494009581ce8e to your computer and use it in GitHub Desktop.
Preview image on input file before upload
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
<input type="file" accept="image/*" onchange="loadFile(event)"> | |
<img id="output"/> | |
<script> | |
var loadFile = function(event) { | |
var output = document.getElementById('output'); | |
output.src = URL.createObjectURL(event.target.files[0]); | |
output.onload = function() { | |
URL.revokeObjectURL(output.src) // free memory | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment