1

From html page, I select a "file index" text file in a local folder (element input type="file").This file list several file names located in the same current folder. How, in javascript, can I get a File descriptor from these other files from their file names ? I try with following code, but I don't know what to do after:

function GetFileHandleFromUrl(localURL) {
var http = new XMLHttpRequest();
http.open('GET', localUrl, false);
http.send(null); // success, return file content

var myFile = ???;
return myFile;

1 Answers1

1

How...can I get a File descriptor from these other files from their file names ?

You can't. You can read the file and get the names from it using the File API (I demonstrate it in this other answer), but you can't then get File instances for those other files in any standard way. The File API only grants you access to files the user has explicitly chosen to give you access to, via an input type=file.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Ok, but If I succeed to read the file content with my code : var http = new XMLHttpRequest(); http.open('GET', localUrl, false); http.send(null); http.response... Can I build a temp file and then create a File descriptor ? – camille rufu Apr 27 '15 at 10:00
  • @camillerufu: Again: No, you can't. Also note that many browsers will prevent your using a local URL (if by "local" you mean `file://...`), because of the SOP. – T.J. Crowder Apr 27 '15 at 10:04
  • Ok, perhaps you are write. But I have my solution. I can work with the content of the file. http.response is enough for me. – camille rufu Apr 27 '15 at 10:55