'Print file on client side

I am using FileSaver.js to print an object array on the client side (HTML/Typescript).

var blob = new Blob([JSON.stringify( marray)], {type: "text/plain;charset=utf-8"});
 saveAs(blob, "Data.txt");

It works fine. The problem is it downloads in the download folder (by default). I want to add a file path along with its name. Any idea? Or another way to do this job. fs is not working in this case. it is not recognizing fs and gives the error fs.writefilesync is not a function



Solution 1:[1]

  1. How do you know what path the user has?

  2. It is not safe. There is no way to "climb" the user's file system

  3. If you open the source code, you will see the simplest implementation scheme there. It's just a click on a link download

    var a = document.createElement('a')
    // ...
    a.href = blob
    // ...
    a.dispatchEvent(new MouseEvent('click'))
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Юрий Копоть