4

I'd like to allow user to select a directory (in which I parse some text files) and store the result(List<File>) in a PERSISTENT storage on the same client so that when the user returns, there is no need to select the same directory again.

During the session selecting the directory (via <input webkitdirectory="..." />) and then accessing the directory and parsing the file already works fine, but I've no idea on what kind of data I shall save in order to retrieve it later. I've tried by using window.webkitResolveLocalFileSystemURL() but wasn't successful so far... any idea?

rudy
  • 81
  • 4
  • It'd be helpful if you spelled out the details a little more. – Shannon -jj Behrens Nov 01 '12 at 18:45
  • The expected work-flow shall be as follow: I'm only interested on *re*-accessing the files in the selected directory – rudy Nov 01 '12 at 22:45
  • You can't do that unless a) the files are in local storage b) the user re-selects the same directory. Sorry, I don't make up the rules, I just point them out ;) – Shannon -jj Behrens Nov 01 '12 at 22:56
  • OK got it, would it be possible to store a link to the directory so that the user only has to re-confirm it (instead of looking for it again)?I'm only interested on *re*-accessing the files in the selected directory when the user access again the app (on the same client) the next time(s) without having to upload (or copy) the files somewhere, this for the following reasons: a) the files can be really big, b) the files in the selected directory can be different (compared to the last session), c) I only need to read and parse the files while the user is actively using the app. – rudy Nov 01 '12 at 23:27
  • I'm sorry, but I really don't think that's possible. In the same way, you can't cache the location of the last *file* the user uploaded. If you do decide to copy the files to local storage, you can give the user the location of the files in local storage. Hence, he can modify them there. – Shannon -jj Behrens Nov 02 '12 at 01:22

1 Answers1

4

Ok, so you're using something like:

<input type="file" id="file-input" webkitdirectory="" directory="">

This lets the user upload a directory. Roughly speaking, here's the code to get the list of files uploaded:

query("#file-input").on.change.add((e) {
  print(e.target.files);
});

It sounds like you already figured that part out.

Really, you just get a list of files. I looked at e.target, and I don't think there's anything in there related to the directory itself. For instance, I don't see anything about the directory name, and it's not as if you suddenly have write access to that directory. You also can't upload files from that directory the next time the user loads the page without him selecting the directory again.

However, what you can do is upload files from that directory and save a copy of those files locally using local file storage.

See also:

By the way, I know I wasn't able to achieve exactly what you wanted, but if you approve of my answer, please accept it. My boss promised to buy me a puppy if I answer 100 questions on Stack Overflow ;)

Community
  • 1
  • 1
Shannon -jj Behrens
  • 4,910
  • 2
  • 19
  • 24
  • Hi Shannon, thanks for the reply unfortunately it does not bring me any further because avoiding to upload the files is exactly what I'm looking for but thanks for your time :-) – rudy Nov 01 '12 at 22:40
  • You don't have to upload the files to the server. "Using the HTML5 Filesystem API" p. 20-21 shows how to copy the files into local storage. Hence, you don't have to actually upload the files to the server, but you can't just read/write to anywhere on the user's harddrive. I hope that clears things up. – Shannon -jj Behrens Nov 01 '12 at 22:55