With the HTML File API we can get a file selected via an <input type="file">
element with var file = evt.target.files[0];
.
How do we get the file content as a string (Something like var content = file.toString()
.
I currently have this code which gets triggered by the input element.onchange
event:
input.onchange = function handleFileSelect(evt) {
var file = evt.target.files[0];
var reader = new FileReader();
console.log("RAW FILE: ", file);
var string = reader.readAsText(file);
console.log("FILE CONTENT: ", string);
}
When I select a file I try to log the contents this happens:
RAW FILE: File
bundle.js:5293 FILE CONTENT: undefined
Thoughts?