unslothai/unsloth · warning · HTTPException

Uploaded file is empty.

Error message

Uploaded file is empty.

What it means

After streaming a browser upload, _persist_upload_stream() finds size == 0: the file transferred but contained no bytes. The just-created empty stored file is removed and HTTP 400 is returned with empty_detail, which _save_upload sets to 'Uploaded file is empty.'.

Source

Thrown at studio/backend/routes/rag.py:146

                block = source.read(1 << 20)
                if not block:
                    break
                size += len(block)
                if cap and size > cap:
                    break
                out.write(block)
    except OSError:
        _remove_stored_upload(stored_path)
        raise
    if cap and size > cap:
        _remove_stored_upload(stored_path)
        raise HTTPException(
            status_code = 413,
            detail = f"File exceeds the {cap // (1024 * 1024)} MB upload limit.",
        )
    if size == 0:
        _remove_stored_upload(stored_path)
        raise HTTPException(status_code = 400, detail = empty_detail)
    return stored_path, filename


def _save_upload(file: UploadFile) -> tuple[str, str]:
    """Persist a browser upload; returns (stored_path, filename)."""
    filename = _sanitize_filename(file.filename or "document")
    return _persist_upload_stream(
        file.file,
        filename,
        empty_detail = "Uploaded file is empty.",
    )


def _save_native_path_upload(lease: str) -> tuple[str, str]:
    """Persist a desktop drop; returns (stored_path, filename).

    The webview never gets to name a path directly: Rust signs the path it saw and we
    re-verify + re-stat that grant here before reading a byte.

View on GitHub (pinned to 203007d190)

Solutions

  1. Check the source file on disk is non-empty (ls -l) and re-create/re-export it if it is zero bytes.
  2. Validate file.size > 0 client-side before enabling the upload button.
  3. In scripts, assert os.path.getsize(path) > 0 before attaching.

Example fix

// before
formData.append('file', fileInput.files[0]); // 0-byte file -> 400
// after
if (fileInput.files[0].size === 0) { showError('File is empty'); return; }
formData.append('file', fileInput.files[0]);
Defensive patterns

Strategy: validation

Validate before calling

if (file.size === 0) { notify('File is empty'); return; } // before any fetch

Type guard

const isNonEmptyFile = (f: File): boolean => f.size > 0;

Prevention

When it happens

Trigger: Submitting a multipart upload whose file part has zero bytes — a placeholder/empty file created by another tool, a truncated file, or a form submission where the file input references an already-deleted file.

Common situations: User selects a 0-byte file left by a failed export or sync client; automated scripts post an empty file handle; tests using fixture files that were never populated.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/c1158d9d632bd003. Report an issue: GitHub.