From c82c74d76c3c0dcc3102e230ac49645345ed91fa Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 4 Sep 2025 10:23:45 -0300 Subject: [PATCH] Enhance upload_user_file endpoint with improved logging and error handling This commit adds detailed debug and error logging to the upload_user_file endpoint, facilitating better tracking of file upload processes and issues. It includes checks for the presence of a file and JWT token, and captures exceptions with traceback information for enhanced debugging. These changes contribute to a more robust and well-documented codebase. --- src/api/langflow_files.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/api/langflow_files.py b/src/api/langflow_files.py index 2d2cfd42..be0a0293 100644 --- a/src/api/langflow_files.py +++ b/src/api/langflow_files.py @@ -8,21 +8,39 @@ async def upload_user_file( request: Request, langflow_file_service: LangflowFileService, session_manager ): try: + print("[DEBUG] upload_user_file endpoint called") form = await request.form() upload_file = form.get("file") if upload_file is None: + print("[ERROR] No file provided in upload request") return JSONResponse({"error": "Missing file"}, status_code=400) + print( + f"[DEBUG] Processing file: {upload_file.filename}, size: {upload_file.size}" + ) + # starlette UploadFile provides file-like; httpx needs (filename, file, content_type) + content = await upload_file.read() file_tuple = ( upload_file.filename, - await upload_file.read(), + content, upload_file.content_type or "application/octet-stream", ) - result = await langflow_file_service.upload_user_file(file_tuple) + jwt_token = getattr(request.state, "jwt_token", None) + print(f"[DEBUG] JWT token present: {jwt_token is not None}") + + print("[DEBUG] Calling langflow_file_service.upload_user_file...") + result = await langflow_file_service.upload_user_file( + file_tuple, jwt_token=jwt_token + ) + print(f"[DEBUG] Upload successful: {result}") return JSONResponse(result, status_code=201) except Exception as e: + print(f"[ERROR] upload_user_file endpoint failed: {type(e).__name__}: {e}") + import traceback + + print(f"[ERROR] Traceback: {traceback.format_exc()}") return JSONResponse({"error": str(e)}, status_code=500)