fix(next): prevent 1MB body limit error when uploading files #15078
+22
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Strip file data from
formStatebefore sending it to thegetFormStateserver action to avoid exceeding Next.js Server Actions' 1MB body size limit.Why?
When uploading files larger than 1MB, the following error occurs:
This happens because:
formState.file.valueformStatetogetFormStatefor validation, field rendering, and permissions checkinggetFormStateis a Server Action, which has a default 1MB body size limit in Next.jsHow?
The fix strips the file value from
formStatebefore sending it to the server action:This is safe because:
buildFormStatehandles field validation, rendering, permissions, and document locking - none of which require the actual file binary(POST /api/[collection])with multipart form data, not through Server ActionsbuildFormState.ts, line 223-226, it preserves the file field from the incoming form state, so passingnulldoesn't break anythingVideo Demo
Before
Arc.2026-01-04.01-41-22.mp4
After
Arc.2026-01-04.01-41-58.mp4
How to test?
Error "Body exceeded 1mb limit"appears immediately when file is selectedFixes #15073