fix(api): resolve HTTP 413 on file uploads larger than 1 MB#204
Open
teamauresta wants to merge 1 commit intoHKUDS:devfrom
Open
fix(api): resolve HTTP 413 on file uploads larger than 1 MB#204teamauresta wants to merge 1 commit intoHKUDS:devfrom
teamauresta wants to merge 1 commit intoHKUDS:devfrom
Conversation
Starlette's MultiPartParser caps individual file parts at 1 MB by default (via the class-level max_file_size / max_part_size attribute). Files larger than this limit are rejected before the route handler runs, which produces an HTTP 413 even when the file is well within the application- level 100 MB cap enforced by DocumentValidator. Patch MultiPartParser.max_file_size to 100 MB at application startup so that Starlette streams larger uploads through to the route handler, which then applies the real per-file constraint via DocumentValidator. The try/except guard keeps compatibility with older Starlette versions that do not expose this attribute. Fixes HKUDS#170
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes HTTP 413 errors when uploading files larger than 1 MB to an existing knowledge base.
Related Issues
Fixes #170
Root Cause
Starlette's
MultiPartParser(≥ 0.31) caps individual file parts at 1 MB by default via the class-levelmax_file_sizeattribute. Files exceeding this are rejected at the framework layer — before the route handler runs — producing a 413 even when the file is well withinDocumentValidator.MAX_FILE_SIZE(100 MB). This is why a 32-byte.txtsucceeds while a 2 MB.pdffails.Changes Made
src/api/main.pystarlette.formparsers.MultiPartParser.max_file_sizeto 100 MB, matching the application-level cap inDocumentValidatortry/except (ImportError, AttributeError)for compatibility with older Starlette versionsChecklist
Additional Notes
DocumentValidator's streaming size check still enforces the real 100 MB per-file limit — this patch simply prevents Starlette from rejecting valid uploads before they reach the route handler.