mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 10:50:35 +08:00
fixing errors in a file uploading flow, as in issue #2799 Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
@ -22,7 +22,7 @@ def upload(file_path, host, flow_id):
|
||||
url = f"{host}/api/v1/upload/{flow_id}"
|
||||
with open(file_path, "rb") as file:
|
||||
response = httpx.post(url, files={"file": file})
|
||||
if response.status_code == 200:
|
||||
if response.status_code == 200 or response.status_code == 201:
|
||||
return response.json()
|
||||
else:
|
||||
raise Exception(f"Error uploading file: {response.status_code}")
|
||||
@ -55,7 +55,7 @@ def upload_file(file_path: str, host: str, flow_id: str, components: list[str],
|
||||
if response["file_path"]:
|
||||
for component in components:
|
||||
if isinstance(component, str):
|
||||
tweaks[component] = {"file_path": response["file_path"]}
|
||||
tweaks[component] = {"path": response["file_path"]}
|
||||
else:
|
||||
raise ValueError(f"Component ID or name must be a string. Got {type(component)}")
|
||||
return tweaks
|
||||
|
||||
@ -95,7 +95,7 @@ def main():
|
||||
raise ImportError("Langflow is not installed. Please install it to use the upload_file function.")
|
||||
elif not args.components:
|
||||
raise ValueError("You need to provide the components to upload the file to.")
|
||||
tweaks = upload_file(file_path=args.upload_file, host=BASE_API_URL, flow_id=ENDPOINT, components=args.components, tweaks=tweaks)
|
||||
tweaks = upload_file(file_path=args.upload_file, host=BASE_API_URL, flow_id=args.endpoint, components=[args.components], tweaks=tweaks)
|
||||
|
||||
response = run_flow(
|
||||
message=args.message,
|
||||
|
||||
Reference in New Issue
Block a user