diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index 4a1cf8eae..10f2f4692 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -8,6 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException, UploadFile from langflow.api.v1.schemas import ( PredictRequest, PredictResponse, + UploadFileResponse, ) from langflow.interface.types import build_langchain_types_dict @@ -57,13 +58,16 @@ async def predict_flow( raise HTTPException(status_code=500, detail=str(e)) from e -@router.post("/upload/{client_id}", response_model=dict, status_code=201) -async def create_upload_file(file: UploadFile, client_id: str): +@router.post("/upload/{flow_id}", response_model=UploadFileResponse, status_code=201) +async def create_upload_file(file: UploadFile, flow_id: str): # Cache file try: - file_path = save_uploaded_file(file.file, file_name=client_id) + file_path = save_uploaded_file(file.file, file_name=flow_id) - return {"file_path": file_path} + return UploadFileResponse( + flowId=flow_id, + file_path=file_path, + ) except Exception as exc: logger.error(f"Error saving file: {exc}") raise HTTPException(status_code=500, detail=str(exc)) from exc diff --git a/src/backend/langflow/api/v1/schemas.py b/src/backend/langflow/api/v1/schemas.py index 714f0df7f..747057a27 100644 --- a/src/backend/langflow/api/v1/schemas.py +++ b/src/backend/langflow/api/v1/schemas.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import Any, Dict, List, Optional, Union from langflow.database.models.flow import FlowCreate, FlowRead from pydantic import BaseModel, Field, validator @@ -101,3 +102,10 @@ class InitResponse(BaseModel): class BuiltResponse(BaseModel): built: bool + + +class UploadFileResponse(BaseModel): + """Upload file response schema.""" + + flowId: str + file_path: Path diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index 9bf66e3da..e736d4275 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -49,4 +49,5 @@ export type InitTypeAPI = { export type UploadFileTypeAPI = { file_path: string; + flowId: string; };