I am trying to download content in a txt file. belwo is the sample code
download() {
let content = "Sample text";
saveAs(new Blob([content], { type: 'text/plain'}), 'sample.txt');
I am using file-saver lib to downlaod the content. all works fine but i need to open the browser popup where user can write/override the file name before downloading it and choose the directory as well where user will save the file.
Any help here will be highly appreciated.
Before directly calling the saveAs() function upon click of the button to download the content, probably you can call a prompt to get the name, and then resume the rest.
download() {
let filename = window.prompt('Please enter a name for your file', 'sample');
let content = "Sample text";
saveAs(new Blob([content], { type: 'text/plain'}), `${filename}.txt`);
}
Or to be more stylish, if you use Bootstrap, you can make use of modals, or any stylish modal of your own.