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
7k stars 680 forks source link

maxFileSize option is not working... #914

Closed KnightKrusty closed 1 year ago

KnightKrusty commented 1 year ago

Support plan

Context

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

its taking care of all things perfectly fine the problem is that i have used below options, where maxFileSize is around 50 - 52mb but when i upload the file bigger than that, the temp file is created and throws an error but file and fields are completely empty so i dont have access to temp file path so i can not remove the temp uploaded file... or the formidable should have deleted the temp created file itself

 multiples: false,
    maxFileSize: 50 * 1024 * 1024,
    allowEmptyFiles: false,
    keepExtensions: true,
    uploadDir: root_upload_path,
    filter: function ({ name, originalFilename, mimetype }) {
      const FILE_TYPES = [
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "application/vnd.ms-excel",
        "application/zip",
        "text/csv",
      ];
      return mimetype && FILE_TYPES.includes(mimetype);
    },
 form.parse(req, async (err, fields, file) => {
      if (err) {
        if (err.code === formidable.errors.biggerThanMaxFileSize) {
           console.log(file) // {}
          console.log(fields) // {}
           reject("File is way too big, Please upload file under 50mb");
          return;
        }
}

What was the result you got?

Bigger files are uploaded inside folder with random string eg c798501cb43645d2a87a5b300.csv

What result did you expect?

file object should have a filepath propety indicating the temp path so the upload file can be removed or it should have removed the tmp file itself...

KnightKrusty commented 1 year ago

Seems to be already solved in latest version: 3.2