Home > front end >  Angular 'saveAs' function
Angular 'saveAs' function

Time:10-15

I am using the following function to save string to a file,

However instead of saving the file to c:/ drive it saves to Downloads folder with the name "C:\Log.txt", how can I specify the location?

  Save(log: string): void {
    saveAs(new Blob([log], { type: "text" }), 'C:\\Log.txt');
  } 

CodePudding user response:

You can't determine where the browser will save the file, independent of the framework you are using.

This happens due to browser security reasons. The user filesystem cannot be accessed by the JavaScript or HTML, otherwise you could place some malware on user's system.

CodePudding user response:

if you are using saveAs from a file-saver library, the second parameter is responsible for the name of the file, not its location.

the browser cannot decide where to save a file, it's unique to the local machine.

  • Related