Created
February 24, 2019 22:15
-
-
Save sorenlouv/b7669ba837533cef231cecbe0ce66349 to your computer and use it in GitHub Desktop.
Bookmark to read local file
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
copy( | |
encodeURIComponent(`(function() { | |
function readLocalFile(e) { | |
const file = e.target.files[0]; | |
if (!file) { | |
alert('No file selected!') | |
} | |
const reader = new FileReader(); | |
reader.onload = function(e) { | |
const contents = e.target.result; | |
localStorage.setItem('mock', contents) | |
}; | |
reader.readAsText(file); | |
} | |
const element = document.createElement('input'); | |
element.type = 'file'; | |
element.addEventListener('change', readLocalFile, false); | |
element.click(); | |
})();`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment