1

As we all know browsers do NOT support repopulating file path to <input/> file across page reload, due to security reasons. But recently chrome 86 has released File System Access API, that simplifies and allows users to read context of the file. If we pair this to File System API (do not confuse them), with the aid of window.requestFileSystem we can persist files between loads, which partially solves this Remember and Repopulate File Input stackoverflow issue.

I wonder if we can repopulate file using FileSystemFileHandle across tab reload. Doing this via requestFileSystem limits us on file size, since we copying file over each select. To be specific, I want to be able to upload and read user selected file after page has been reloaded w/o saving it to localFileSystem.

I also posted this question to github issues.

deathangel908
  • 8,601
  • 8
  • 47
  • 81

1 Answers1

2

The GitHub issue had an answer, reposting slightly edited here to save others a click:

You can store the file handle you get from showOpenFilePicker in IndexedDB and read that back on subsequent page loads. In general regaining access might require the user to accept another permission prompt, but for the case of a page reload the current Chrome implementation will likely keep the permission grant around long enough to not require extra prompts. We have some ideas to extend that to session restore as well, but nothing concrete currently.

DenverCoder9
  • 2,024
  • 11
  • 32
  • Please provide some code. Because the answer aims to store file content as I understand which is the opposite what I'm asking – deathangel908 Dec 16 '20 at 16:15
  • Then I guess I don't understand what you mean by "repopulate". By storing the file handle you can write to it again (you need to grant access again, but not select the file in the picker again). – DenverCoder9 Dec 16 '20 at 16:26
  • If file is 10 gb, indexedDB will copy content of the file, will consume 10gb of disc space, and time to copy the file. If it's not what you mean, please provide some code of how to do it. – deathangel908 Dec 16 '20 at 20:42
  • 1
    @deathangel908 it's just the handle, not file data – Dee Feb 05 '23 at 08:48