Finish is happening after all the file events. Your code does a console.log after the streams are read.
When you use my console.log at the beginning of a file event, you should see that they are all logged before finish. It's all about the asynchronous nature of javaScript. On Oct 3, 2014, at 8:12 AM, [email protected] wrote: > I need to get 'finish' event. when all files already saved. Your console may > show properly, but it's not a 'finish' event :( > My trouble is 'finish' activated not in right time, as well as 'end' doesn't > fire :( > Can you help me with that? > > On Friday, 3 October 2014 18:53:31 UTC+4, Jake Wolpert wrote: > Finish should happen before all your console log calls, but not before mine! > > It takes time to read the files. > > > > busboy.on('file', function (fieldname, file, filename) { > fstream = fs.createWriteStream(__dirname + '/../static/uploaded/' + > filename); > console.log('file ' + filename + ' uploading'); // mine > file.pipe(fstream); > fstream.on('close', function(){ > console.log('file ' + filename + ' uploaded'); /yours > files.push(filename); > }); > }); > > On Oct 3, 2014, at 6:27 AM, [email protected] wrote: > >> Hello,. >> I trying to upload few files through one input[type=file] with attribue >> 'multiple'. All work fine but 'finish' event firing before realy all work >> done. Does anyone know how to fix it? >> >> My server code: >> app.post('/multiupload', function(req, res) { >> var fstream; >> var files = []; >> var busboy = new Busboy({headers: req.headers}); >> busboy.on('file', function (fieldname, file, filename) { >> fstream = fs.createWriteStream(__dirname + '/../static/uploaded/' + >> filename); >> file.pipe(fstream); >> fstream.on('close', function(){ >> console.log('file ' + filename + ' uploaded'); >> files.push(filename); >> }); >> }); >> >> >> busboy.on('end', function(){console.log('END')}); >> >> >> busboy.on('finish', function(){ >> console.log('finish, files uploaded ', files); >> res.redirect('back'); >> }); >> req.pipe(busboy); >> }); >> >> My console.log info: >> file 111.gz uploaded >> file 222.mp4 uploaded >> file 333.jpg uploaded >> finish, files uploaded [ '111.gz', '222.mp4', '333.jpg' ] >> file 444 uploaded >> file 555.jpg uploaded >> >> >> -- >> Job board: http://jobs.nodejs.org/ >> New group rules: >> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >> Old group rules: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> --- >> You received this message because you are subscribed to the Google Groups >> "nodejs" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/nodejs/2bb9066f-e117-4ed8-98b3-407ee4c4237b%40googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. > > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/304c4d70-b57c-4f38-aa71-1856309a638a%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/7C84AC17-3759-41BE-A098-68095CF9FEDF%40gmail.com. For more options, visit https://groups.google.com/d/optout.
