Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
ask user to write file name before downloading txt file in angular

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda