Working with the HTML5 files Api

Working with the HTML5 files Api
0

#1

Happy Sunday everyone!
I’m preparing to make an advanced markup viewer with react and electron, etc. I’d like to be able to read and write files. At least, I’d definitely like to load files. I’ve tried using the html5 localFiles Api, but I’ve had trouble getting the data in order to view a file. Any ideas? I’ll make a pen here: https://codepen.io/b3u/pen/MqpBBz


#2

I solved it, partly. The following code block, though I’m not sure how, reads files through the fileReader object.

function drop(e) {
  ...
var files = e.dataTransfer.files;
  
  var reader = new FileReader();
  reader.onload = (function(file) {
    return function(e) 
    {output.innerText = e.target.result}
  })(files[0]);
  reader.readAsText(files[0])
}
})