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

195
Visualizações
Sending zip file over http

I am a python developer. I am very new with nodejs and I am trying to send a zip file to client as http response. After lot of research I created zip file from my data in following way:

  var fileDest = "file.zip";
  var file = fs.createWriteStream(fileDest);
  
  http.get(fileUrlStr.url, function(res) {
     
     if (res.statusCode !== 200) {
        var err = new Error('file download failed');
        err.fileName = fileDest;
        err.statusCode = res.statusCode;
        return cb(err);
     }
     res.on('data', function(data) {
        file.write(data);
     }).on('end', function() {
        file.end();
        var zipFile = fs.readFileSync(fileDest, 'utf8').toBuffer();
        cb(zipFile);
     });
  }).on('error', function (err) {
     console.log('downloadFile error');
     fs.unlink(fileDest);
     err.fileName = fileDest;
     cb(err);
  });

The cb() function has following response configuration :

  cb(response){  
        statusCode: statusCode,
        headers: {
            "Access-Control-Allow-Headers": "Content-Type,Authorization,X-Amz-Date,X- 
            Api-Key,X-Amz-Security-Token",
            "Access-Control-Allow-Methods": "DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT",
            "Access-Control-Allow-Origin": "*"
        },
        body: JSON.stringify(response)
  }

But on the client side , i recieved undefined as response. Any hint or help would be very appreciated.

about 4 years ago · Juan Pablo Isaza
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