Skip to content

fix(api): resolve HTTP 413 on file uploads larger than 1 MB#240

Open
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
JasonOA888:fix/170-starlette-multipart-size
Open

fix(api): resolve HTTP 413 on file uploads larger than 1 MB#240
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
JasonOA888:fix/170-starlette-multipart-size

Conversation

@JasonOA888
Copy link
Copy Markdown

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-level max_file_size attribute. Files exceeding this are rejected at the framework layer — before the route handler runs — producing a 413 even when the file is well within DocumentValidator.MAX_FILE_SIZE (100 MB). This is why a 32-byte .txt succeeds while a 2 MB .pdf fails.

Changes Made

deeptutor/api/main.py

  • Added a startup block that patches starlette.formparsers.MultiPartParser.max_file_size to 100 MB, matching the application-level cap in DocumentValidator
  • Wrapped in try/except (ImportError, AttributeError) for compatibility with older Starlette versions
  • Includes full inline explanation with reference to this issue and the Starlette source

Testing

  • Verified the patch is applied at module import time
  • Code follows existing patterns in the codebase

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (inline comments)

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:在已有知识库再上传文件出错:Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)

1 participant