[Bug Report] bodySizeLimit Rejects Files at Exact Size Due to HTTP Protocol Overhead #93989
jucieltonsantos-orbia
started this conversation in
Ideas
Replies: 1 comment
-
|
I've added #94137 - The framework can only reliably enforce the total request size; it cannot know where the file bytes end and the multipart framing begins without parsing the body, which defeats the purpose of the limit check. A percentage based approach is not the right direction either, as the overhead is not proportional to the request body size, but the number of items, their names, boundary length, etc... That's why I think documentation is the way to go here. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
1.- Allow uploads of files with size exactly equal to
serverActions.bodySizeLimitwithout triggering a413 Payload Too Largeerror.2. Reduce confusion for developers who set the limit expecting it to allow files up to exactly X MB.
3. Clarify and/or implement a safe buffer (protocol overhead) in the request body size calculation.
Non-Goals
Background
Currently, when setting
bodySizeLimit: '5mb', uploads of files exactly at that size fail with error 413 because Next.js compares the raw stream size with the limit without accounting for HTTP protocol overhead frommultipart/form-data(boundary delimiters, field metadata, headers, etc.). This overhead typically adds 0.5–3% to the actual payload sent.The current behavior forces developers to configure limits with manual "padding" — something that goes against user expectations and is not clearly documented. This is especially confusing for those migrating from other frameworks (Express, Fastify, etc.) where body parsers naturally account for this margin.
Current workarounds:
6mbto allow 5MB files)There's no official way to guarantee uploads up to the exact limit without trial-and-error.
Proposal
Option 1: Add Automatic Overhead Buffer (Recommended)
Add 5–10% overhead tolerance when comparing
totalSizewithbodySizeLimit:Beta Was this translation helpful? Give feedback.
All reactions