0

I am trying to upload multiple files on ftp using node.js. My uploading start successfully and i see the file uploaded in the server location, but after some time not receiving the success message, at browser end i am getting this error "Error 324 (net::ERR_EMPTY_RESPONSE): but in server my files are still uploading on ftp.

Here is the upload log for the process:

uploaded Audio >>1 >>1572528
uploaded Audio >>1 >>1637949
uploaded Audio >>1 >>1703388
uploaded Audio >>1 >>1768865
uploaded Audio >>1 >>1834167
PUT /user/album/deliverAudio - - ms - -   
               // as soon as this line execute I get EMPTY_RESPONSE_ERROR in browser
uploaded Audio >>1 >>1899552

Below is the partial code for the process:

sync.map(req.body.tracks, function(track, callback) {
    var data = '';
    var filename = '';
    var readableAudioStream = fs.createReadStream(track.trackpath.track_path);
    c.put(readableAudioStream,track.filename, function(err) {
      if (err) {
        return callback(err);
      }
      callback(null);
    });
    readableAudioStream.on('data', function(chunk) {
      data += chunk;
      console.log('uploaded Audio >>'+track.track_no+' >>'+data.length);
    });
}, function(err, results) {
  console.log('audio error');
  console.log(err);
  done(err);
});
Ilesh Patel
  • 2,053
  • 16
  • 27

1 Answers1

0

I think you're probably giving a NULL/undefined response to the HTTP request. Try sending an actual payload in the response.

Try

c.put(readableAudioStream,track.filename, function(err) {
  if (err) {
    return callback(err);
  }
  callback(null, { success: true }); // Give an actual payload response from the completion of the upload
});

Then later, handle the results from the request:

function (err, results) {
   if (err) res.send(500, err);
   res.json(results);
}
Adam Terlson
  • 12,610
  • 4
  • 42
  • 63
  • at where I have to put it? – Ilesh Patel May 21 '15 at 18:18
  • I have one more step after this step in Async.waterfall, so what should I pass? – Ilesh Patel May 21 '15 at 18:19
  • I'm not entirely sure I can answer that without full context, but my point is that you should try sending an actual payload response rather than undefined/null. Just send anything and I'm thinking that might fix it. If you're handling the `results` param in the next step, it should get the `{ success: true }` object and send that with `res.json(results)`. – Adam Terlson May 21 '15 at 18:22