5

以下のコードでは、終了イベントのみが呼び出されます。


var Busboy = require('connect-busboy');

app.use(Busboy());

app.post('/fileupload', function(req, res) {
  var fstream;

  req.pipe(req.busboy);

  req.busboy.on('error', function(err){
    console.log(err);
  });

  req.busboy.on('field', function(fieldname, val, valTruncated, keyTruncated) {
    console.log("fieldname: " + fieldname); 
  });

  req.busboy.on('file', function (fieldname, file, filename) {
    console.log("filename: " + filename); 
    fstream = fs.createWriteStream(__dirname + '/files/' + filename);
    file.pipe(fstream);
    fstream.on('close', function () {
      res.redirect('back');
      console.log("fileupload end");
    });
  });

  req.busboy.on('finish', function() {
    console.log('Done parsing form!');
  });
});
4

1 に答える 1