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

242
Vistas
Download File using express and fetch doesn't work

I try to download a file using nodejs and Javascript. When I call the URL in the Browser, the file gets downloaded. When I call this Endpoint in my javascript file using fetch, the download doesn't work

NodeJS Endpoint

app.get("/download", function (req, res, next) {
    res.download(
        filepath
    );
});

Javascript Call

const downloadFile = async (path) => {
await fetch("http://localhost:8080/download", {
    method: "Get",
})
    .then((response) => {
        console.log(response);
    })
    .catch((error) => {
        console.log(error);
    });

};

Do you have any suggestions?

Thank you very much!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When you make a request using Ajax then the response is passed back to the JavaScript code for handling.

If you want to do something with the file the server has sent you, then you need to write JavaScript to do something with it.

Your JavaScript logs the response object then stops.

The browser will only automatically render it in the viewport / save it to downloads if you type the URL into the address bar / click a link / etc. Doing Ajax explicitly avoids that automatic handling.

So the solution here is: Don't use Ajax. Use a link, or assign a value to location, etc.

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