{"record":{"id":"317fe11eb0370ea6","repo":"iflytek/astron-agent","slug":"uploaded-file-is-empty","errorCode":null,"errorMessage":"Uploaded file is empty","messagePattern":"Uploaded file is empty","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/ragflow/ragflow_utils.py","lineNumber":293,"sourceCode":"                return await RagflowUtils._download_url_file(file_input)\n            else:\n                raise ValueError(\n                    f\"Unsupported file input: {file_input}. \"\n                    \"Only HTTP/HTTPS URLs are supported for string input.\"\n                )\n        else:\n            # Handle UploadFile objects\n            file_content = await file_input.read()\n            filename = file_input.filename or \"uploaded_file\"\n\n            logger.info(\n                \"Processing uploaded file: %s, size: %d bytes\",\n                filename,\n                len(file_content),\n            )\n\n            if len(file_content) == 0:\n                raise Exception(\"Uploaded file is empty\")\n\n            # Reset file pointer for potential future reads\n            await file_input.seek(0)\n\n            return file_content, filename\n\n    @staticmethod\n    def _normalize_expected_chunk_count(raw_count: Any) -> Optional[int]:\n        \"\"\"Return a usable non-negative metadata count when one is available.\"\"\"\n        try:\n            expected_count = int(raw_count) if raw_count is not None else None\n        except (TypeError, ValueError):\n            return None\n        if expected_count is not None and expected_count < 0:\n            return None\n        return expected_count\n\n    @staticmethod","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/ragflow/ragflow_utils.py#L275-L311","documentation":"process_file in ragflow_utils.py reads the uploaded UploadFile into memory and raises a generic Exception when the resulting byte buffer has length 0. This guards downstream RAGFlow ingestion from receiving a zero-byte document that would silently produce no chunks. It means the upload reached the server but contained no content.","triggerScenarios":"Calling process_file with an UploadFile whose streamed body is empty — e.g. the client posted a zero-byte file, the multipart form field pointed at no data, or a prior consumer already read the stream without seeking back.","commonSituations":"Frontend sends an empty file placeholder; a curl/script uploads an empty file; a file was truncated during transfer; an intermediary step consumed the stream leaving nothing to read.","solutions":["Check the uploaded file size on the client/server before calling process_file and reject zero-byte files with a clear 400 response","Verify the multipart form field actually carries the file bytes (correct field name, enctype=multipart/form-data)","If another read happened before process_file, ensure file_input.seek(0) is called first","Log filename and client metadata to find the source of empty uploads"],"exampleFix":"// before\ncontent, name = await process_file(file)\n// after\nraw = await file.read()\nif not raw:\n    raise HTTPException(status_code=400, detail=\"Uploaded file is empty\")\ncontent, name = await process_file(file)","handlingStrategy":"validation","validationCode":"raw = await file.read()\nif not raw:\n    raise ValueError(f\"uploaded file {file.filename!r} is empty\")\nawait file.seek(0)","typeGuard":"def is_nonempty(data: bytes) -> bool:\n    return isinstance(data, bytes) and len(data) > 0","tryCatchPattern":"try:\n    content, name = await process_file(file)\nexcept Exception as e:\n    if \"Uploaded file is empty\" in str(e):\n        return JSONResponse(status_code=400, content={\"detail\": \"File is empty\"})\n    raise","preventionTips":["Check file size client-side before upload (input.accept + size check)","Reject zero-byte files at the API layer with a 400","Never reuse a stream without seek(0) after a prior read","Log upload sizes to spot clients repeatedly sending empty files"],"tags":["file-upload","validation","ragflow"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}