{"record":{"id":"83011f25e54793bc","repo":"HKUDS/DeepTutor","slug":"the-upload-has-no-filename","errorCode":null,"errorMessage":"The upload has no filename.","messagePattern":"The upload has no filename\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"deeptutor/api/routers/reading.py","lineNumber":183,"sourceCode":"@router.get(\"/materials\", response_model=list[MaterialInfo])\nasync def list_materials() -> list[MaterialInfo]:\n    store = _store()\n    try:\n        return [_info(store, manifest) for manifest in store.list_materials()]\n    except Exception as exc:\n        raise _http_error(exc) from exc\n\n\n@router.post(\"/materials\", response_model=MaterialDetail)\nasync def upload_material(file: UploadFile = File(...)) -> MaterialDetail:  # noqa: B008\n    \"\"\"Ingest an uploaded document and return it ready to read.\n\n    The upload is streamed to a temp file with a running size check, so an\n    oversized file is rejected before it is fully buffered rather than after.\n    \"\"\"\n    filename = (file.filename or \"\").strip()\n    if not filename:\n        raise HTTPException(status_code=400, detail=\"The upload has no filename.\")\n\n    tmp_dir = Path(tempfile.mkdtemp(prefix=\"dt-reading-\"))\n    tmp_path = tmp_dir / Path(filename).name\n    written = 0\n    try:\n        with tmp_path.open(\"wb\") as sink:\n            while chunk := await file.read(_UPLOAD_CHUNK):\n                written += len(chunk)\n                if written > MAX_MATERIAL_BYTES:\n                    raise HTTPException(\n                        status_code=413,\n                        detail=(\n                            f\"{filename} exceeds the \"\n                            f\"{MAX_MATERIAL_BYTES // (1024 * 1024)} MB limit.\"\n                        ),\n                    )\n                sink.write(chunk)\n        if written == 0:","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/reading.py#L165-L201","documentation":"Upload guard in POST /materials: the multipart UploadFile carried no usable filename (empty or whitespace after strip), so the store has no name to key the material on and the request is rejected before any bytes are staged.","triggerScenarios":"Thrown at deeptutor/api/routers/reading.py:183 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Client: send the multipart part with a real filename attribute (e.g. filename in Content-Disposition)","Server: synthesize a fallback name (material-<uuid>.<ext>) when the filename is absent but bytes are valid","Client: verify the file input element actually has a file selected before submitting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","contentChangedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}