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

168
Visualizações
How to download a file with particular name via using download attribute?

I'm trying to download file, which is generated by server in maner as below:

public downloadZip(): void{
    const link = document.createElement('a');
    link.setAttribute(
      'href',
      `/srv/genZip?id=${this.id}`
    );
    link.setAttribute('download', '123.zip');
    link.click();
  }

But it doesn't work... Does anyone have an idea where I'm wrong?

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

0

You can't absolutely drive this process, you can only provide hints to the browser.

The browser has a couple of different places it may look for a filename for the download:

  • The server's Content-Disposition header, which can include a filename, for instance
    Content-Disposition: attachment; filename="123.zip"
    or
    Content-Disposition: attachment; filename*="123.zip"

  • The download attribute

As far as I can tell, there's no specification saying which should have preference, so to maximize the browsers across which your code will work, I'd specify the same name in both.

Underscoring that, there's this note in MDN's coverage of Content-Disposition above:

Note: Chrome, and Firefox 82 and later, prioritize the HTML <a> element's download attribute over the Content-Disposition: inline parameter (for same-origin URLs). Earlier Firefox versions prioritize the header and will display the content inline.

So if your server is returning Content-Disposition: inline and you're seeing the resource loaded inline (not downloaded), you may be using an older copy of Firefox or a browser that does the same thing.

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