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.

File still uploads even when it exceeds fileSize limit

See original GitHub issue

For testing purposes, I’m uploading a 102kB file with limits setup like so:

...
const limits = {
    fileSize: 5,
};

const upload = multer({storage: storage, fileFilter: fileFilter, limits: limits});
...

Clearly that exceeds the 5 byte limit, but I’m finding that the file still gets saved without any errors, except that the saved file is 5 bytes in size, so it seems something just writes the first part of the file and then gives up. I’m assuming this isn’t an intended feature, but do correct me if I’m wrong.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
adf0001commented, Apr 25, 2019

Hmm, it seems like this test case should cover that, and it passes

https://github.com/expressjs/multer/blob/master/test/issue-232.js

Would you be able to submit a failing test case? Then I can take a look at fixing it

line changed: form.append(‘file’, util.file(‘huge.rar’)) //huge.rar is a file of 2600M (2.6G)

mocha --timeout 120000 issue-232.js

Issue #232 √ should report limit errors (24565ms)

1 passing (25s) //<------ too long

When I test in Chrome locally, I get 0% to 100% uploading status report from Chrome, and at 100%, get a “MulterError: File too large”. The error emit after all the file has uploaded.

windows 7, node v6.5, multer 1.4.1

1reaction
munawarbcommented, Oct 25, 2019

Hi @FINDarkside, You’re welcome 😃. Last I tested which was a couple months ago with Firefox, it timed out when Formidable closed the connection on a large file upload. So yup it looks like browsers are still not following the spec. Here’s some Formidable middleware for Express that works well for me. It’s better than using express-formidable because you get more control by implementing it yourself:

// This middleware will add body to the request object and files will be contained in the files field.
// The upload directory is also defined here.
app.use((req, res, next) => {
	const form = new formidable.IncomingForm({keepExtension: true, maxFileSize: 2.5*1024*1024, uploadDir: uploadDirectory});
	form.parse(req, (err, body, files) => {
		if (err)
			return next(err);
		Object.assign(req, {body, files});
		next();
	});
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the uploaded file exceeds ...
In order to fix this error, you need to increase the file size upload limit. That is, you need to increase the value...
Read more >
How to Fix the File Size Exceeds Limit Error 0x800700DF ...
2. Use the Registry Editor ... If you get the File exceeds the limit allowed and cannot be saved error when you transfer...
Read more >
How To Fix Uploaded File Exceeds Max Size Error
Trying to upload a big file into WordPress and getting a message telling you the file is too big, exceeds the maximum upload...
Read more >
How to Fix This Error: The Uploaded File Exceeds ...
The error occurs when you are trying to upload a large file which can be an image, plugin, theme, or video. If the...
Read more >
Attachment size exceeds the allowable limit error - Outlook
This limit prevents your computer from continually trying to upload very large attachments that exceed the limits of most Internet service ...
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