iflytek/astron-agent · error · Exception
Uploaded file is empty
Error message
Uploaded file is empty
What it means
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.
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
Example fix
// before
content, name = await process_file(file)
// after
raw = await file.read()
if not raw:
raise HTTPException(status_code=400, detail="Uploaded file is empty")
content, name = await process_file(file) Defensive patterns
Strategy: validation
Validate before calling
raw = await file.read()
if not raw:
raise ValueError(f"uploaded file {file.filename!r} is empty")
await file.seek(0) Type guard
def is_nonempty(data: bytes) -> bool:
return isinstance(data, bytes) and len(data) > 0 Try / catch
try:
content, name = await process_file(file)
except Exception as e:
if "Uploaded file is empty" in str(e):
return JSONResponse(status_code=400, content={"detail": "File is empty"})
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- LONG_CONTENT_CHAT_ID_ERROR
- LONG_CONTENT_WRONG_BUSINESS_TYPE
- LONG_CONTENT_MISS_FILE_INFO
- LONG_CONTENT_FILE_SIZE_OUT_LIMIT
- 8001
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/317fe11eb0370ea6.
Report an issue: GitHub.
Appendix: source
Thrown at core/knowledge/infra/ragflow/ragflow_utils.py:293
return await RagflowUtils._download_url_file(file_input)
else:
raise ValueError(
f"Unsupported file input: {file_input}. "
"Only HTTP/HTTPS URLs are supported for string input."
)
else:
# Handle UploadFile objects
file_content = await file_input.read()
filename = file_input.filename or "uploaded_file"
logger.info(
"Processing uploaded file: %s, size: %d bytes",
filename,
len(file_content),
)
if len(file_content) == 0:
raise Exception("Uploaded file is empty")
# Reset file pointer for potential future reads
await file_input.seek(0)
return file_content, filename
@staticmethod
def _normalize_expected_chunk_count(raw_count: Any) -> Optional[int]:
"""Return a usable non-negative metadata count when one is available."""
try:
expected_count = int(raw_count) if raw_count is not None else None
except (TypeError, ValueError):
return None
if expected_count is not None and expected_count < 0:
return None
return expected_count
@staticmethodView on GitHub (pinned to 5e758547a8)