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

302
Views
How to ask for permission to download files on NextJS?

I have the following endpoint:

baseurl.com/api/v1/datasheet/format

Accesing this url will download specific information based on the datasheet. In Express, for example, I return this method if the format = json:

const generateJSON = (res, data) => {
    res.header('Content-Type', 'application/json');
    res.attachment('example.json');
    return res.send(data);
}

This works fine, but it downloads automatically the file as "example.json" without asking the user for his permission to download the file

My purpose is to have a button on my frontend (using NextJS) that will ask the user if he wants to download the file (the classic download or cancel prompt for downloads) and then open the file explorer, etc.

How can I do this? Is this something from the backend or frontend?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use Content-disposition: attachment; filename=example.json to trigger a Save as DIalog box.

const generateJSON = (res, data) => {
    res.header('Content-Type', 'application/json');
    res.header('Content-disposition', 'attachment');
    res.attachment('example.json');
    return res.send(data);
}


The first parameter in the HTTP context is either inline (default value, indicating it can be displayed inside the Web page, or as the Web page) or attachment (indicating it should be downloaded; most browsers presenting a 'Save as' dialog, prefilled with the value of the filename parameters if present).

via https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#:~:text=The%20first%20parameter,parameters%20if%20present).

over 4 years ago · Santiago Trujillo 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!