{"record":{"id":"4366cd168e2c465d","repo":"HKUDS/DeepTutor","slug":"file-sanitized-filename-exceeds-maximum-size-l","errorCode":null,"errorMessage":"File '{sanitized_filename}' exceeds maximum size limit of {size_str}","messagePattern":"File '(.+?)' exceeds maximum size limit of (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"deeptutor/api/routers/knowledge.py","lineNumber":433,"sourceCode":"                            except Exception as pb_exc:\n                                logger.debug(\n                                    \"PocketBase file upload failed for '%s': %s\",\n                                    dest.name,\n                                    pb_exc,\n                                )\n                    continue\n\n                file_path = dest_dir / sanitized_filename\n                max_size = DocumentValidator.MAX_FILE_SIZE\n                written_bytes = 0\n\n                file.file.seek(0)\n                with open(file_path, \"wb\") as buffer:\n                    for chunk in iter(lambda: file.file.read(8192), b\"\"):\n                        written_bytes += len(chunk)\n                        if written_bytes > max_size:\n                            size_str = format_bytes_human_readable(max_size)\n                            raise HTTPException(\n                                status_code=400,\n                                detail=(\n                                    f\"File '{sanitized_filename}' exceeds maximum size \"\n                                    f\"limit of {size_str}\"\n                                ),\n                            )\n                        buffer.write(chunk)\n\n                DocumentValidator.validate_upload_safety(\n                    sanitized_filename, written_bytes, allowed_extensions=allowed_extensions\n                )\n                written_file_paths.append(file_path)\n                uploaded_files.append(rel_name)\n                uploaded_file_paths.append(str(file_path))\n\n                # Mirror file to PocketBase when enabled (best-effort, non-blocking).\n                if _pb_sync and kb_name:\n                    try:","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/knowledge.py#L415-L451","documentation":"Raised while streaming an uploaded file to disk in _save_uploaded_files: the cumulative byte count exceeded the endpoint's max_size limit, so the write is aborted mid-stream with HTTP 400. The limit is formatted human-readably in the message.","triggerScenarios":"Uploading any file (or zip member landing via _save_uploaded_files) whose size exceeds the configured upload cap; the check fires mid-copy after 8192-byte chunks, so files only slightly over the limit still trigger it.","commonSituations":"Large PDFs/videos pushed to a KB with a conservative cap; zip members extracted after upload that individually exceed the limit; default limits not raised after increasing server disk.","solutions":["Compress, split, or trim the file below the configured max size","Raise the upload size limit in the server settings if the deployment allows it","For documents, export a lighter version (fewer pages/images) and retry"],"exampleFix":"# before\nupload('huge_scan.pdf')  # 800MB\n# after\nupload('huge_scan_compressed.pdf')  # < limit","handlingStrategy":"validation","validationCode":"import os\n\ndef under_limit(path, max_size):\n    return os.path.getsize(path) <= max_size","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check file size against the configured cap before upload","Compress or split large documents","Surface the server's limit in the UI so users know the cap"],"tags":["upload","size-limit","http-400"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}