0

I need to create a text or json file and save file to user selected location in local machine using Javascript. I used below code but it downloads the file to Downloads directory

download(text:any, name:any, type:any) {
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click();

}

Below is what I am looking

  1. My application has a diagram and the diagram data can be exported as json data
  2. User want to save this data to a file in selected location. Lets say C:\Temp, This will help in sharing the diagram data with other users and they can import it into their application

We want to implement notepad File -> SaveAs kind of functionality here

Mohan
  • 233
  • 1
  • 8
  • 21
  • 1
    Possible duplicate of [Using HTML5/Javascript to generate and save a file](https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file) – david25272 Nov 20 '17 at 23:49
  • Take a look at [FileSaver.js](https://github.com/eligrey/FileSaver.js/) – charlietfl Nov 20 '17 at 23:56
  • Not sure whether requirement is clear or not. I need to implement notepad File -> SaveAs functionality in my application. When user saves data it should create a file in specific location selected by user lets say C:\Temp. **All the examples mentioned above are creating file but it downloads to a default location which is Downloads folder. If I provide filename with Path (C:\Temp\test.json) then its creating file as C_Temp_test.json in Downloads folder**. Let me know if you have any suggestions for this requirement – Mohan Nov 21 '17 at 15:17

0 Answers0