multer icon indicating copy to clipboard operation
multer copied to clipboard

[question] File too large error when file is exactly the size of fileSize

Open ChengLawson opened this issue 1 year ago • 1 comments

I would like to allow files up to and including 10mb (10,485,760 bytes) and have specified fileSize with this number of bytes. When I tried uploading a file exactly 10485760 bytes in size, I received the "File too large" error. If I increase fileSize by 1 byte then I can upload the file.

Should I specify fileSize with a number 1 byte large than my intended maximum allowed file size?

Multer verson: "multer": "^1.4.5-lts.1"

Code:

const storage = multer.memoryStorage();
const maxSize = 10 * 1024 * 1024; // 10MB
const upload = multer({ storage, limits: { fileSize: maxSize } }).any();
...
upload(req, res, (err) => {
      if (err) {
       logger.error(`${err?.message ? err?.message : err}`);
      }
...
}

File used: 10mb.txt

ChengLawson avatar Aug 12 '22 09:08 ChengLawson

Adding 1 byte is a valid workaround. I think you should open an issue at busboy too as fileSize in the limits object is supposed to be the maximum file size in bytes.

UnKnoWn-Consortium avatar Sep 30 '22 06:09 UnKnoWn-Consortium