2

In a web application I am working on I would like to be able to download files, modify them localy and reupload them to the server.
To make it as easy as possible for the users, I would like them to choose the download location and use a single button to upload the changes afterwards.
My current apporach is the following:

  1. Use window.showSaveFilePicker to choose location and get a FileSystemFileHandle
  2. Download the content and write it to the FileSystemFileHandle
  3. Show a button which allows to upload the changes using FileSystemFileHandle#getFile to get the modified content.

This approach works pretty well but the user has to manually search and open the file after the download and I would like to support them in this step and make it as simple as possible.
Ideally the file should automatically be opened with the default application after the download but I couldn't find a way to do that.
One idea was to open the file in a new tab using the file://-URL, allowing the browser to decide what to do but the FileSystemFileHandle does not seem to expose the absoulte path.
Is there any way to open the downloaded file with the default application? If not, what other possibilities are there to make the mentioned use case as simple as possible?

Thanks in advance

EDIT: I found that you can open certain applications using special urls like ms-excel:ofe|u|file://path/to/file.xls. This would be enough for most use cases but for this to work I would need to get the file url from a FileSystemFileHandle.

Robert P
  • 9,398
  • 10
  • 58
  • 100
  • 1
    why do you need File System Access API at all? The way you described it, it's not like you're writing files to the filesystem directly via javascript, files get edited manually by the end-user. – GrafiCode May 25 '22 at 09:47
  • Thats true but the File System Access API allows me to automatically upload the changes as I already have a handle to the file. Without it, the user needs to manually choose the file again. – Robert P May 25 '22 at 09:49

1 Answers1

0

For security reasons, there is no way for a Web app to open local apps. In the future, though, once file change events are implemented, you can await changes to the file, and then re-open it. This should solve your use case.

DenverCoder9
  • 2,024
  • 11
  • 32
  • Thank you for your answer. This solution could help with the automatic upload but if I am using a filehandle, the upload of the changes is only a single click. The disadvantage of the filehandle solution is, that the browser does not show the downloaded file and the user has to manually navigate to the file and open it with an editor. On the other hand, the solution without filehandles require a more complex sequence to upload the changes (you need to manually select the changed file). I am looking for a solution that combines the best of the two solutions but it does not seem to be possible – Robert P Jun 20 '22 at 15:08
  • Correct, the full flow you have in mind isn't possible; and for a very good reason. You generally wouldn't want random websites to open operating system applications. I was outlining the closest (future) flow you can achieve. You'd need to instruct the user to open the file manually, but everything else would work as you have imagined. – DenverCoder9 Jun 21 '22 at 07:06
  • I understand the reason behind it, random websites should not open native applications. But there are a few things about it: - I can open a native application using special URLs (for example "ms-excel:ofe") - The user actively gives me access to a specific file when I use "showSaveFilePicker" So whats missing is the local URL to the saved file, which would allow me to open the file using the special URL. But as thats not possible for now, I guess I have to look for the next best solution. Anyways, thank you for the information about the file change events. – Robert P Jun 21 '22 at 08:00