Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda