Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!