I am testing out a file reader for one of my html projects. I want the JavaScript program to read a particular file immediately, instead of the file being selected by the user (in this case, me). I have the p tag and the id of the tag as 'file'. When I run the program in my browser (Safari), I get the error message
TypeError: Argument 1 ('blob') to FileReader.readAsText must be an instance of Blob
I have been looking all over the internet to find a solution, but I just can't find anything. I was thinking of doing my program with python and then inserting it into my webpage with trinket.io's iframe tag. But then I sort of gave up on that idea. Here is the code:
var reader = new FileReader();
var fileToRead = "quotes.txt";
// attach event, that will be fired, when read is end
reader.addEventListener("loadend", function() {
document.getElementById('file').innerText = reader.result;
});
reader.readAsText(fileToRead);
I would like the output of this program to show the contents of the text file, yet when I run it in my browser it gives me a blank screen. I hope there is a solution out there.
FileReader.readAs<DataURL,Text,Blob,ArrayBuffer>(<Blob>)expectsBlobas parameter passed, as the error message states. See File API. Is"quotes.txt"a local or remote file?