expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.56k stars 1.05k forks source link

Error: 413 Request Entity Too Large #1166

Closed suntong closed 1 year ago

suntong commented 1 year ago

Same problem I can't exceed 1MB on a single() file upload despite setting 8MB:


const upload = multer({
dest: '/tmp/uploads',
limits: {
fieldSize: 8 * 1024 * 1024,
},
});

app.post('/messages/upload', upload.single('image'), async (req, res) => { // never get here as multer rejects as 413 (too large) }


>
>`fileSize` not set as indicated as infinity, only `fieldSize` being limited to 1MB by default.
>
>I can confirm that defining `fileSize` lower than 1MB will result in files being rejected if they exceed the specified size, but it seems impossible to have anything greater than 1MB.

_Originally posted by @keiranmraine in https://github.com/expressjs/multer/issues/562#issuecomment-389642971_
suntong commented 1 year ago

Reopening #562 as I'm having the exact same problem, yet all answers from it, as well as the answers from #344 #413& #602, are not working for me.

I've provided a minimal reproduction case at

https://github.com/suntong/express-simple-example/tree/testing/upload/big I.e., https://github.com/suntong/express-simple-example/blob/testing/upload/big/index.js

The code finishes fine, but I'm wondering why I'm getting the following as well as returned json:

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>openresty</center>
</body>
</html>

And how can I get rid of such error.

suntong commented 1 year ago

I've also tried to add the following suggested "solution",

// fixing "413 Request Entity Too Large" errors
app.use(express.json({limit: "10mb", extended: true}))
app.use(express.urlencoded({limit: "10mb", extended: true, parameterLimit: 50000}))

But removed them as they are not working either.

alamjamal commented 1 year ago

hi, can you specify which server are you using?

suntong commented 1 year ago

I'm running it on a powerful MS Azure server, a private one, not any public servers

I tried to give you the result of cpupower info, but got:

Intel's performance bias setting needs root privileges

Ah, got it:

System memory size: 7GiB Cpu: Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz

suntong commented 1 year ago

I've provided a fully functional minimal reproduction case, anyone can give it a try to verify, if you want.

LinusU commented 1 year ago

@suntong if you look at the html error page you will se an indication where the error originates from:

<hr><center>openresty</center>

It seems like you are running OpenResty in front of Node.js, and it's OpenResty that is limiting your post body.

Closing since the problem is outside of Multer

suntong commented 1 year ago

I searched the whole project folder for KW: "openresty" but found nothing. I've provided a fully functional minimal reproduction case, can anyone try it please?

LinusU commented 1 year ago

@suntong I can upload a 13 MB file with your minimal reproduction case.

$ git clone git@github.com:suntong/express-simple-example.git
$ cd express-simple-example
$ git checkout testing/upload/big
$ npm install
$ npm start

(then in another terminal)

$ curl -X POST http://localhost:3399/upload -F file=@my-large-file.zip
suntong commented 1 year ago

Oh, thanks a lot for trying @LinusU,

would you verify your index.js is the same as that of https://github.com/suntong/express-simple-example/blob/testing/upload/big/index.js please?

As the index.js is in the testing/upload/big branch. Just want to double check as I don't see branch switching in your above commands. thx.

LinusU commented 1 year ago

@suntong it's the same. I did forgot to put it in the above commands, but I did run it 👌

Will update the comment...