Skip to content

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

Merged
merged 3 commits into from
Jan 19, 2018

Conversation

Haggus
Copy link
Contributor

@Haggus Haggus commented Dec 1, 2017

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

@coveralls
Copy link

coveralls commented Dec 1, 2017

Coverage Status

Coverage decreased (-2.0%) to 93.617% when pulling 10263ab on Haggus:handle-file-limit into c3c41ec on richardgirges:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.0%) to 93.617% when pulling 10263ab on Haggus:handle-file-limit into c3c41ec on richardgirges:master.

@richardgirges
Copy link
Owner

Hi @Haggus thanks for the PR! It looks good - would you mind adding a unit test for this update?

Cheers

@coveralls
Copy link

coveralls commented Dec 6, 2017

Coverage Status

Coverage increased (+2.3%) to 97.872% when pulling 91d944f on Haggus:handle-file-limit into c3c41ec on richardgirges:master.

@coveralls
Copy link

coveralls commented Dec 6, 2017

Coverage Status

Coverage increased (+0.1%) to 95.745% when pulling 1c52f44 on Haggus:handle-file-limit into c3c41ec on richardgirges:master.

@Haggus
Copy link
Contributor Author

Haggus commented Dec 6, 2017

Here you go! :)

@ShakMR
Copy link
Contributor

ShakMR commented Jan 2, 2018

Why not, instead of ending the request, adding some kind of attribute to the file (limitReached = true or truncated = true) to let us know so we can handle the error in our side?

What about something like this https://github.com/ShakMR/express-fileupload/blob/22a7d5cce1e8b857363543a04be8d3f6f671f130/lib/index.js#L76?
Complete list of changes here: https://github.com/ShakMR/express-fileupload/pull/1/files

@richardgirges
Copy link
Owner

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.

@Haggus
Copy link
Contributor Author

Haggus commented Jan 3, 2018

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 truncated flag, I think busboy may already have this implemented.

@tianjianchn
Copy link

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 next function.
Hope it helps.

@richardgirges richardgirges merged commit 4eaccda into richardgirges:master Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

limit fileSize
5 participants