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

192
Views
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
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!