Last active
April 7, 2025 19:44
-
-
Save rustyvz/31606a38b9334f0178fc22d341d4dff9 to your computer and use it in GitHub Desktop.
Display Uploaded Images
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
| <!-- Use the FileReader API's readAsDataURL method to show uploaded images --> | |
| <input type="file" id="uploaded-file" /> | |
| <div id="result"></div> | |
| <script> | |
| function readImage() { | |
| const fileReader = new FileReader(); | |
| const file = document.getElementById("uploaded-file").files[0]; | |
| if (file) { | |
| fileReader.readAsDataURL(file); | |
| } | |
| fileReader.addEventListener( | |
| "load", | |
| () => { | |
| const img = document.createElement("img"); | |
| img.src = fileReader.result; | |
| document.getElementById("result").append(img); | |
| }, | |
| { once: true } | |
| ); | |
| } | |
| document.getElementById("uploaded-file").addEventListener("change", readImage); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment