Last active
February 22, 2023 21:04
-
-
Save robert-hoffmann/c52a68cb2bfe01f717104b4a5e9912be to your computer and use it in GitHub Desktop.
upload/download files client-side only
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
| <input type="file" onchange="fileSelected(this)" accept="application/JSON" /> | |
| <a | |
| download="settings.json" | |
| target="_blank" | |
| >download</a> | |
| <pre> | |
| <code></code> | |
| </pre> |
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
| const preview = document.querySelector('code'); | |
| const download = document.querySelector('a'); | |
| function fileSelected(ele) { | |
| const file = ele.files[0]; | |
| const fr = new FileReader(); | |
| fr.onload = () => { | |
| preview.innerText = fr.result; | |
| download.href = window.URL.createObjectURL(file); | |
| }; | |
| fr.readAsText(file); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment