Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added util for loading file based on the path #451

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/workflow_manager/endpoint/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
from hashlib import md5, sha256
from io import BytesIO
from pathlib import Path
from typing import Any, Optional

Expand Down Expand Up @@ -384,6 +385,18 @@ def handle_final_result(
if connection_type == WorkflowEndpoint.ConnectionType.API:
results.append({"file": file_name, "result": result})

def load_file(self, input_file_path: str) -> tuple[str, BytesIO]:
connector: ConnectorInstance = self.endpoint.connector_instance
connector_settings: dict[str, Any] = connector.connector_metadata
source_fs: fsspec.AbstractFileSystem = self.get_fsspec(
settings=connector_settings, connector_id=connector.connector_id
)
with source_fs.open(input_file_path, "rb") as remote_file:
file_content = remote_file.read()
file_stream = BytesIO(file_content)

return remote_file.key, file_stream

@classmethod
def add_input_file_to_api_storage(
cls, workflow_id: str, execution_id: str, file_objs: list[UploadedFile]
Expand Down
Loading