How can I display a Save As dialog in an Electron App?

前端 未结 3 2493
野趣味
野趣味 2021-02-19 04:34

I am writing a NodeJS Electron App to be distributed on all platforms. I have a download button that I would like to pop open a Save As dialog with the file being provided from

3条回答
  •  醉话见心
    2021-02-19 05:08

    Take a look at this page on the electron docs https://github.com/atom/electron/blob/master/docs/api/dialog.md

    There is a section about dialog.showSaveDialog

    Then you can use the URL from the save dialog with a function similar to the one below to save it to that location.

    session.on('will-download', function(event, item, webContents) {
      event.preventDefault();
      require('request')(item.getUrl(), function(data) {
        require('fs').writeFileSync('/somewhere', data);
      });
    });
    

    Found on this page https://github.com/atom/electron/blob/master/docs/api/session.md

提交回复
热议问题