richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

(Fix) Stopped additional responses from being sent if a limit handler exists #264

Closed Benez11 closed 3 years ago

Benez11 commented 3 years ago
richardgirges commented 3 years ago

Thank you! I will get this pushed up on the next release shortly.

mayurpunjabi commented 3 years ago

I updated to latest version 1.2.1, but I am still getting "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" after assigning limitHandler. Can someone help?

app.use(fileUpload({ limits: { fileSize: 3 * 1024 * 1024 }, limitHandler: (req, res, next) => res.json({ 'success': false, 'message': 'File size limit has been reached' }) }));

therealsujitk commented 1 year ago

I'm getting this issue too, looks like the next() function is still being called after an abort. @richardgirges is there a fix for this? for now I've fixed this with in my function.

if (res.headersSent) {
  return;
}