fix(api): resolve HTTP 413 on file uploads larger than 1 MB#240
Open
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
Open
fix(api): resolve HTTP 413 on file uploads larger than 1 MB#240JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
Conversation
Starlette >= 0.31 caps individual file parts at 1 MB by default via MultiPartParser.max_file_size. This causes HTTP 413 errors for files exceeding 1 MB, even when DocumentValidator.MAX_FILE_SIZE (100 MB) allows larger uploads. This patch raises the framework-level limit to match the application cap, allowing uploads up to 100 MB to reach the route handler where proper size validation occurs. Fixes HKUDS#170 Co-authored-by: Jason L <JasonOA888@users.noreply.github.com>
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
deeptutor/api/main.pystarlette.formparsers.MultiPartParser.max_file_sizeto 100 MB, matching the application-level cap inDocumentValidatortry/except (ImportError, AttributeError)for compatibility with older Starlette versionsTesting
Checklist
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.