From ccc64ac6b772a09945ef9b0f283956c1ccf5f1ec Mon Sep 17 00:00:00 2001 From: Suleiman Elkhoury <108065141+suleimanelkhoury@users.noreply.github.com> Date: Wed, 7 May 2025 14:48:49 +0200 Subject: [PATCH] Update provider.py Add S3_ENABLE_TAGGING to add tags optionally based on the env file. --- backend/open_webui/storage/provider.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/storage/provider.py b/backend/open_webui/storage/provider.py index 17d7f5ab5..5c85f88bc 100644 --- a/backend/open_webui/storage/provider.py +++ b/backend/open_webui/storage/provider.py @@ -17,6 +17,7 @@ from open_webui.config import ( S3_SECRET_ACCESS_KEY, S3_USE_ACCELERATE_ENDPOINT, S3_ADDRESSING_STYLE, + S3_ENABLE_TAGGING, GCS_BUCKET_NAME, GOOGLE_APPLICATION_CREDENTIALS_JSON, AZURE_STORAGE_ENDPOINT, @@ -140,18 +141,19 @@ class S3StorageProvider(StorageProvider): ) -> Tuple[bytes, str]: """Handles uploading of the file to S3 storage.""" _, file_path = LocalStorageProvider.upload_file(file, filename, tags) - tagging = {"TagSet": [{"Key": k, "Value": v} for k, v in tags.items()]} + s3_key = os.path.join(self.key_prefix, filename) try: - s3_key = os.path.join(self.key_prefix, filename) self.s3_client.upload_file(file_path, self.bucket_name, s3_key) - self.s3_client.put_object_tagging( - Bucket=self.bucket_name, - Key=s3_key, - Tagging=tagging, - ) + if S3_ENABLE_TAGGING and tags: + tagging = {"TagSet": [{"Key": k, "Value": v} for k, v in tags.items()]} + self.s3_client.put_object_tagging( + Bucket=self.bucket_name, + Key=s3_key, + Tagging=tagging, + ) return ( open(file_path, "rb").read(), - "s3://" + self.bucket_name + "/" + s3_key, + f"s3://{self.bucket_name}/{s3_key}", ) except ClientError as e: raise RuntimeError(f"Error uploading file to S3: {e}")