Skip to content

Commit

Permalink
Handle empty attachment (ComposioHQ#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaavee315 authored Aug 3, 2024
1 parent 7db71e2 commit a3a9421
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions python/composio/client/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,15 +1010,20 @@ def execute(
modified_params[param] = base64.b64encode(file_content).decode(
"utf-8"
)
elif file_uploadable and isinstance(value, str) and os.path.isfile(value):
with open(value, "rb") as file:
file_content = file.read()
encoded_data = base64.b64encode(file_content).decode("utf-8")
encoded_data_with_filename = {
"name": os.path.basename(value),
"content": encoded_data,
}
modified_params[param] = encoded_data_with_filename
elif file_uploadable and isinstance(value, str):
if os.path.isfile(value):
with open(value, "rb") as file:
file_content = file.read()
encoded_data = base64.b64encode(file_content).decode("utf-8")
encoded_data_with_filename = {
"name": os.path.basename(value),
"content": encoded_data,
}
modified_params[param] = encoded_data_with_filename
elif value == "":
pass
else:
return {"error": f"File with path {value} not found"}
else:
modified_params[param] = value

Expand Down

0 comments on commit a3a9421

Please sign in to comment.