question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fileSize limit on fastify-multipart did not throw error

See original GitHub issue

I don’t know if I use it correctly or not but it is just pass through if I passing file with size higher than limit.

/*
 * other code
 */

fastify.post('/upload', async function (req, reply) {
    const data = await req.file({
      limits: {
        fileSize: 1 * 1024 * 1024,  // 1mb limit
      }
    })

    await pump(data.file, fs.createWriteStream(data.filename))

    reply.send()
})

It write file to my directory, when I expect it to throw error

  • node version: 14.15.3
  • fastify version: 3.9.2
  • fastify multipart version: 3.3.1
  • os: WSL

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
mcollinacommented, Jan 25, 2021

Yes, busboy marks a file with truncated when the file limit was reached. In my opinion, an error should be thrown but I can’t remember why we didn’t implement it. According to busboy the library will only emit a limit event on the file object.

I guess we should error this.

2reactions
StarpTechcommented, Feb 21, 2021

I think the current behavior is correct because we can only guarantee error handling for a stream when we iterate over all parts until onEnd is called. In all other cases, the user can check for file.truncated after the stream was consumed. The req.file API is error-prone because it can’t report the final error.

hi all, I just try the new version 4.0.0 but unfortunately the problem still exist when using req.file, req.files and req.parts but works when using req.saveRequestFiles.

I couldn’t reproduce it. It is only valid for req.file. Please provide a reproducible example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fileSize limit on fastify-multipart did not throw error
Coming soon: A brand new website interface for an even better experience!
Read more >
fastify-multipart - npm
If you set a fileSize limit, it is able to throw a RequestFileTooLargeError error when limit reached. fastify.post('/upload/files', ...
Read more >
Fastify multipart/form-data error: "body must be object"
I'm using fastify-multer and JSON Schema to submit multipart form data that may include a file. No matter what I do, Fastify keeps...
Read more >
fastify/busboy - NPM Package Overview - Socket.dev
Start using Socket to analyze @fastify/busboy and its 1 ... If a configured file size limit was reached, stream will both have a...
Read more >
File upload | NestJS - A progressive Node.js framework
Warning Multer cannot process data which is not in the supported multipart format ( multipart/form-data ). Also, note that this package is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found