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

303
Visualizações
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 Respostas
Responde à pergunta

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 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