unslothai/unsloth · warning · HTTPException

No file was provided.

Error message

No file was provided.

What it means

_resolve_document_upload() dispatches between the two upload channels: if native_path_lease is set it attaches by native path, otherwise it requires a multipart file part. When both are absent — no file part and no lease — it raises HTTP 400 'No file was provided.' before anything is persisted.

Source

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

    filename = _sanitize_filename(grant.canonical_path.name)
    try:
        with open(grant.canonical_path, "rb") as source:
            return _persist_upload_stream(
                source,
                filename,
                empty_detail = "Dropped file is empty.",
            )
    except OSError as exc:
        raise HTTPException(status_code = 400, detail = "Dropped file could not be read.") from exc


def _resolve_document_upload(
    file: UploadFile | None, native_path_lease: str | None
) -> tuple[str, str]:
    if native_path_lease:
        return _save_native_path_upload(native_path_lease)
    if file is None:
        raise HTTPException(status_code = 400, detail = "No file was provided.")
    return _save_upload(file)


def _remove_stored_upload(stored_path: str | None) -> None:
    """Best-effort cleanup for files saved by _save_upload."""
    if not stored_path:
        return
    try:
        uploads = os.path.realpath(str(rag_uploads_root()))
        target = os.path.realpath(stored_path)
        if os.path.isfile(target) and os.path.commonpath([uploads, target]) == uploads:
            os.remove(target)
    except Exception:  # noqa: BLE001 - DB/index deletion has already succeeded.
        logger.warning("failed to remove RAG upload %s", stored_path, exc_info = True)


def _is_managed_preview_path(stored_path: str) -> bool:
    uploads = os.path.realpath(str(rag_uploads_root()))

View on GitHub (pinned to 203007d190)

Solutions

  1. Attach a file part or a valid nativePathLease form field (exact alias spelling) to the request.
  2. Make the file input required client-side so the request cannot fire empty.
  3. In scripts, double-check curl -F field names against the endpoint signature.

Example fix

# before
curl -X POST .../documents -F ocr=true  # 400 No file was provided
# after
curl -X POST .../documents -F file=@doc.pdf -F ocr=true
Defensive patterns

Strategy: validation

Validate before calling

if (!file && !nativePathLease) { throw new Error('attach a file or provide nativePathLease'); }

Prevention

When it happens

Trigger: POSTing the document-upload endpoint with neither the 'file' multipart part nor the 'nativePathLease' form field — e.g. an empty form submit, a request built without attaching either field, or a client that names the fields differently.

Common situations: Frontend form allows submit with no file selected; field-name mismatch (client sends 'native_path_lease' while the backend expects alias 'nativePathLease'); curl/script that forgets -F file=@...; automated tests posting empty bodies.

Related errors


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