Home > Software design >  How to save/write a file from html with javascript?
How to save/write a file from html with javascript?

Time:11-17

I am doing an easy desktop app to crop photos, in order to do this I have a npm project with a few dependencies and an HTML file and launch the browser with the following command, chromium-browser --disable-web-security.

The problem is that when the app execute this code:

crop(event) {
        cropper.getCroppedCanvas().toBlob((blob) => {
        saveAs(new Blob([blob] ), './a.jpg');
      });

And this download automatically the file in the download folder instead of the same folder where the index file is.

Any idea about how can I set a relative path to download the file?

Thanks.

CodePudding user response:

If you are just targeting chrome, there is a way. You can use Chrome's FS functionality

https://web.dev/file-system-access/

If you first load the file using this API, you will have the FileHandler object to use when you want to save

  • Related