I have JavaScript that invokes the File Open dialogue, and the a handler to process the selected file, and store the filename into a database (as a ‘recent files’ list).
The handler gets the file name from event.target.files[0]
, opens it, reads the contents.
When retrieving the recent files list from the database, I would like to render the file as href
link, which when clicked would invoke the same handler as if the file had been selected from the File Open Dialogue.
The handler is as follows:
function readFile(e) {
var file = e.target.files[0];
if (!file) return;
var reader = new FileReader();
reader.readAsText(file);
.
.
}
How can I insert the filename into e.target.file[0]
so I can call the same readFile
function as is called when selecting the file from File Open Dialogue?
Currently I have this:
<a href=''
onclick='e.target.file[0] = file_path; readFile(e);'>
file-name </a>