-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
feat: req.file throws filesize error #207
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach looks good to me, I've left a few notes.
test/multipart-small-stream.test.js
Outdated
@@ -30,7 +30,7 @@ test('should throw fileSize limitation error on small payload', async function ( | |||
const part = await req.file({ limits: { fileSize: 2 } }) | |||
await sendToWormhole(part.file) | |||
if (part.file.truncated) { | |||
reply.code(500).send() | |||
reply.code(413).send() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ops, simply my carelessness
@@ -504,6 +504,9 @@ function fastifyMultipart (fastify, options, done) { | |||
let part | |||
while ((part = await parts()) != null) { | |||
if (part.file) { | |||
if (part.file.truncated) { | |||
throw new RequestFileTooLargeError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure that the only condition for the file being truncated is that it is too large? Maybe it should be a different error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken, Busboy the lib used under the hood sets the property truncated only when the stream reaches fileSizeLimit.
Here the busboy docs:
If a configured file size limit was reached, stream will both have a boolean property truncated (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add a comment?
If you specify it in the function |
A test is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
can you check why CI is failing? |
Yes, I am doing it, the ci fails on windows for |
I have installed a windows machine on Virtualbox with node 12.21.0 as the CI, to reproduce the error, but everything works fine. |
@StarpTech could you take a look? |
Sorry, I had no time yesterday. |
Feature proposal:
Allow req.file to throw an error when the file is bigger than the limit
closes #196
Checklist
npm run test
andnpm run benchmark
and the Code of conduct