-
Notifications
You must be signed in to change notification settings - Fork 260
Handle 'limit' event when file is over fileSize #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1 similar comment
Hi @Haggus thanks for the PR! It looks good - would you mind adding a unit test for this update? Cheers |
Here you go! :) |
Why not, instead of ending the request, adding some kind of attribute to the file ( What about something like this https://github.com/ShakMR/express-fileupload/blob/22a7d5cce1e8b857363543a04be8d3f6f671f130/lib/index.js#L76? |
I do like the idea of allowing the error to be handled by the user. What do you think @Haggus ? @ShakMR since you already coded it, would you mind sending a PR? I wonder if there would also be value in providing the user with either option. If we go with that, we can create a new configuration option and merge both solutions in. |
I think a configuration option to turn on automatic throw would be the best solution here. Personally I prefer that the lib throws an error as soon as it hits the limit, but as @ShakMR mentioned, this might not be what everyone wants. Also, when it comes to |
Maybe trying these codes below: .on('limit', () => {
const err = new Error('Request Entity Too Large');
err.statusCode = 413;
next(err);
}); Since express can handle this error and respond right status code(413). and if user wants to handle that exception, he can use custom |
When 'limit' event fires, it returns 413 (Payload Too Large). Let me know if there is anything you'd like to do differently :)
This should close #40