Skip to content

Instantly share code, notes, and snippets.

@sqren
Created February 24, 2019 22:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Bookmark to read local file
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