0

Is there any javascript or Chrome extension API, that would allow downloading a file to a specific folder under a specific name? The intent is to improve upon the saver of TiddlyWiki and/or provide similar "self-overriding file" functionality in order to allow easily saving back on top of a file previously opened in the browser.

In https://stackoverflow.com/a/9834261/2075630 a method for displaying a "Save file" dialog for a blob is demonstrated. However, this method can only suggest a file name.

  • It cannot determine the folder for which the Save dialog will be displayed. Depending on user-settins, it will default to either automatically downloading the file to some Downloads folder, or displaying the Save dialog.
  • In either case, if the file name already exists, chrome will save the file as filename (1).dat, filename (2).dat, etc by default.

With this facility it isn't possible to create a confortable "Save-back" function that allows to:

  1. Open a file from the local filesystem, and
  2. Overwrite it with changed contents, without the risk of creating duplicates.

Notes

  • There seems to be an experimental Writeable Files API [stackoverflow,google] in Chrome, that will enable something similar. I'm not clear though, on whether Chrome considers file:// URIs as secure context.

  • The chrome.fileSystem API might provide the necessary features, but it should not be available to extensions.

kdb
  • 4,098
  • 26
  • 49
  • 1
    I'm pretty sure you are out of luck here. Allowing JS to set a path would be a big security problem. i.e.: saving a file to an auto-run folder – Wendelin Oct 02 '19 at 18:47
  • @Wendelin I assumed as much. I was hoping there might be a constrained API, e.g. "give program access to user-selected directory" or "allow local file to overwrite itself". The latter seems unlikely, as apps like "TiddlyWiki" are a niche case. – kdb Oct 02 '19 at 18:54
  • There seems to be an experimental Writeable Files API [\[stackoverflow](https://stackoverflow.com/a/53887513/2075630)[,google\]](https://developers.google.com/web/updates/2019/08/native-file-system) in Chrome, that will enable something similar. I'm not clear though, on whether Chrome considers `file://` URIs as secure context. I will have to look into whether the [`chrome.fileSystem`](https://developer.chrome.com/apps/fileSystem) API is exposed to extensions... – kdb Oct 02 '19 at 20:42

1 Answers1

0

I think you need to build a browser extension to achieve this. For example, here is a Chrome extension API to handle the file download https://developer.chrome.com/docs/extensions/reference/downloads/#method-download

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 30 '22 at 18:27
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30945672) – David Salomon Feb 06 '22 at 06:17