Skip to content

Instantly share code, notes, and snippets.

@sorenlouv
Created February 24, 2019 22:15
Show Gist options
  • Save sorenlouv/b7669ba837533cef231cecbe0ce66349 to your computer and use it in GitHub Desktop.
Save sorenlouv/b7669ba837533cef231cecbe0ce66349 to your computer and use it in GitHub Desktop.
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