javascripthtmlnative-file-system-api-js

How to provide default filename for showSaveFilePicker


I am wanting to provide a spinner in my web app as I download a file from the server and then save it using the File System Access API.

I can do this using the showSaveFilePicker() but it seems very odd that I can't specify a default filename. I know what the filename of the file that I am downloading is so I want to suggest that to the user as the name of the file they should save it as. At the moment my user needs to come up with a name each time they are downloading it.

It seems very odd that I can't do this! There must be a way!


Solution

  • This is now supported as of Chrome 91 and you can specify a suggested file name as part of the parameters:

    const handle = await self.showSaveFilePicker({
      suggestedName: 'README.md',
      types: [{
        description: 'Markdown',
        accept: {
          'text/markdown': ['.md'],
        },
      }],
    });
    

    On older versions the suggestedName will just silently be ignored, so it's safe to add it today!