node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7.01k stars 680 forks source link

maxFileSize #797

Closed xHyroM closed 2 years ago

xHyroM commented 2 years ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

    const form = new formidable.IncomingForm({ uploadDir: './uploads', keepExtensions: true, maxFileSize: maxFileSize, allowEmptyFiles: false });

    form.parse(req, (err: any, fields: any, files: any) => {
      if (err) {
        return res.status(413).json({
          name: 'TOO LARGE',
          message: 'Maximum allowed size is 1 GB'
        })
      }

      res.status(200).json({ 
        name: 'OK',
        message: 'File has been uploaded', 
        data: {
          path: files.file.newFilename
        } 
      })
    });

What was the result you got?

It throws an error, but it saves an empty file in the uploads/ folder.

What result did you expect?

It throws an error, the file is not saved

GrosSacASac commented 2 years ago

Thanks I will look into it

xHyroM commented 2 years ago

Fixed by https://github.com/node-formidable/formidable/pull/798

GrosSacASac commented 2 years ago

published 3.2.1

GrosSacASac commented 2 years ago

No

aderchox commented 1 year ago

Ah this is frustrating, if the latest is v2, then it made sense to be at least in v2 as well...

aderchox commented 1 year ago

I just used express-fileupload instead.

Thanks, but it's suddenly working for me on v2 as well.

KnightKrusty commented 1 year ago

Dammit. I'm not gonna change my entire import system. I guess I'll have to look for another module.

There is dynamic import so you can import inside your function like this

async function uploadfile() {
  const formidable = await import("formidable");
}