unslothai/unsloth · error · HTTPException
Empty file not allowed
Error message
Empty file not allowed
What it means
HTTP 400 raised by POST /seed/upload-unstructured-file when the uploaded file body is zero bytes (len(content) == 0 after await file.read()). Empty documents cannot be chunked or previewed, so they are rejected up front.
Source
Thrown at studio/backend/routes/data_recipe/seed.py:454
@router.post("/seed/upload-unstructured-file")
async def upload_unstructured_file(
file: UploadFile = FastAPIFile(...), block_id: str = Form(...)
) -> UnstructuredFileUploadResponse:
_validate_safe_id(block_id, "block_id")
original_filename = file.filename or "upload"
ext = Path(original_filename).suffix.lower()
if ext not in UNSTRUCTURED_ALLOWED_EXTS:
raise HTTPException(
400,
f"Unsupported file type: {ext}. Allowed: {', '.join(sorted(UNSTRUCTURED_ALLOWED_EXTS))}",
)
content = await file.read()
size_bytes = len(content)
if size_bytes == 0:
raise HTTPException(400, "Empty file not allowed")
if size_bytes > UNSTRUCTURED_RECIPE_UPLOAD_MAX_BYTES:
raise HTTPException(
413,
f"File too large ({size_bytes} bytes). Maximum is {UNSTRUCTURED_RECIPE_UPLOAD_MAX_LABEL}.",
)
block_dir = UNSTRUCTURED_UPLOAD_ROOT / block_id
ensure_dir(block_dir)
current_total = _get_block_total_size(block_dir)
if current_total + size_bytes > UNSTRUCTURED_RECIPE_UPLOAD_TOTAL_MAX_BYTES:
raise HTTPException(
413,
f"Total upload limit ({UNSTRUCTURED_RECIPE_UPLOAD_TOTAL_MAX_LABEL}) exceeded",
)
file_id = uuid4().hex
raw_path = block_dir / f"{file_id}{ext}"View on GitHub (pinned to 203007d190)
Solutions
- Check file.size > 0 in the picker/submit handler before uploading.
- If the file should have content, re-download or re-save it and verify in a text editor.
- Log the filename and size client-side to identify which selection was empty.
Example fix
// before
formData.append('file', selectedFile);
// after
if (selectedFile.size === 0) { alert('File is empty'); return; }
formData.append('file', selectedFile); Defensive patterns
Strategy: validation
Validate before calling
if (file.size === 0) { reportError(`${file.name} is empty`); return; }
upload(file); Type guard
function isNonEmptyFile(f: File): boolean { return f.size > 0; } Try / catch
On 400 'Empty file not allowed', skip the file and flag it in the UI; never re-send the same 0-byte body.
Prevention
- Filter zero-size selections before building the form data.
- Validate downloads actually produced bytes before forwarding them to upload.
When it happens
Trigger: Multipart upload where the file part has a filename but empty body — an empty file picked in a file dialog, a truncated stream, or a programmatically created 0-byte file.
Common situations: User creates a placeholder .txt that was never written to; frontend aborts the read but still submits; upstream download failed silently leaving a 0-byte file that gets forwarded.
Related errors
- Unsupported file type: {ext}. Allowed: {allowed}
- {str(exc)}
- Dropped dataset is empty
- No dataset file was provided
- Empty upload payload
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/a5e65162b9fe3f6b.
Report an issue: GitHub.