0

I use BusBoy plugin to handle file upload. It registers a handler for event 'file' which is happening when the file has been uploaded completely,then the handler will do the next operation. But when the upload file is undefined,event handler is registered but event 'file' never happens. It will take along time for process to stop handling this request. When I keep on doing such thing for more than five times,the node process will halt for several minutes, it will come to normal after a few minutes.

Then how can I handle this situation in NodeJS process? Don't tell me never to upload undefined, when file upload failed, I think such situation will also take place.

2 Answers 2

1

you can use 'finish' event to stop processing

busboy.on('finish', function() {
 //your code to stop processing
});

This 'finish' event will trigger when all files/fields events in the uploading (form) data have been triggered. (Trigger is ignored if file/field is undefined).

further it is recommended to recheck in your case to pipe your node request through busboy

req.pipe(busboy);
Sign up to request clarification or add additional context in comments.

1 Comment

Though set a handler for finish event didn't help, but you inspired me,thank you anyway.My solution is followed
0

I have solved this problem through this. Set a variable flag for 'file' event, when the event happened the flag will be set true in its handler. Because 'file' event happens before req.end event,so I register a handler for the end event of req.

req.on('end',function(){
    if(!flag){
         res.json({
            ....        
         });
    }

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.