From 797c5bbc13e861c19c727c4d35b139e4697310b5 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Tue, 16 Jan 2024 14:20:54 +0100 Subject: [PATCH] fix(agent/workspace): Fix GCS workspace binary file upload --- .../autogpt/autogpt/app/agent_protocol_server.py | 1 - autogpts/autogpt/autogpt/file_workspace/gcs.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.py index 29ab004a..6abd9c8c 100644 --- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py +++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py @@ -339,7 +339,6 @@ class AgentProtocolServer: """ Create an artifact for the task. """ - data = None file_name = file.filename or str(uuid4()) data = b"" while contents := file.file.read(1024 * 1024): diff --git a/autogpts/autogpt/autogpt/file_workspace/gcs.py b/autogpts/autogpt/autogpt/file_workspace/gcs.py index c6ff3fc9..f1203cd5 100644 --- a/autogpts/autogpt/autogpt/file_workspace/gcs.py +++ b/autogpts/autogpt/autogpt/file_workspace/gcs.py @@ -75,10 +75,15 @@ class GCSFileWorkspace(FileWorkspace): """Write to a file in the workspace.""" blob = self._get_blob(path) - if isinstance(content, str): - blob.upload_from_string(content) - else: - blob.upload_from_file(content) + blob.upload_from_string( + data=content, + content_type=( + "text/plain" + if type(content) is str + # TODO: get MIME type from file extension or binary content + else "application/octet-stream" + ), + ) if self.on_write_file: path = Path(path)