1

In my web app, the user can import their images from a folder on their computer. That's working well. Now I want to save that info to localStorage so that when the user resumes using the app in a future session, they do not once again have to import their images. Is this possible? If so, can I just store the folder name or do I have to store the folder name and all filenames?

Jim Andrews
  • 375
  • 1
  • 2
  • 14
  • prob a duplicate of https://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page – Andrew Lohr Dec 15 '17 at 20:09
  • No that question is about saving actual files to localStorage. My question is about saving path and filename info to localStorage. – Jim Andrews Dec 15 '17 at 20:12

1 Answers1

1

One choice would be to store the local paths in local storage, and load them on their next session. You'd need to store each one, or just the folder path if you want to automatically load all files in the folder. This would fail if the files are moved/deleted before the next session.

Another approach would be to convert the image to base64 string, and store that string instead. This would still work if the files are moved/deleted, but will consume much more storage (keep in mind there is a ~10MB cap).

Glenn Barnett
  • 2,031
  • 1
  • 21
  • 31
  • if you save the path in local storage how do you get the image back? I thought the browser can't access the filesystem – Andrew Lohr Dec 15 '17 at 20:14
  • If I just store the folder path, can i, in a subsequent session, retrieve all the filenames without some user action allowing it? – Jim Andrews Dec 15 '17 at 20:15
  • 1
    hmm, no - the browser won't have the authority to list files in a directory (could be used maliciously). so you should save all the paths – Glenn Barnett Dec 15 '17 at 20:35