From f05cb2fb7dedaad68e0bdda2545e123f82a4b855 Mon Sep 17 00:00:00 2001 From: sasi Date: Fri, 23 Aug 2024 11:20:48 +0530 Subject: [PATCH] minio download func added --- helpers/supabaseClient.py | 31 ++++++++++++++++++++++++++++--- requirements.txt | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/helpers/supabaseClient.py b/helpers/supabaseClient.py index e6f0ffc..a3f5522 100644 --- a/helpers/supabaseClient.py +++ b/helpers/supabaseClient.py @@ -181,10 +181,35 @@ def convert_dict(self,data): return data except Exception as e: print(e) - raise Exception + raise Exception - def getStatsStorage(self, fileName): - return self.client.storage.from_("c4gt-github-profile").download(fileName) + def getStatsStorage(file_name,bucket_name): + try: + from minio import Minio + from minio.error import S3Error + + # Set up MinIO client + ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY") + SECRET_KEY = os.getenv("MINIO_SECRET_KEY") + MINIO_API_HOST = os.getenv("MINIO_API_HOST") + bucket_name = "c4gt-github-profile" + + minio_client = Minio( + endpoint=MINIO_API_HOST, + access_key=ACCESS_KEY, + secret_key=SECRET_KEY, + secure=False + ) + + response = minio_client.get_object(bucket_name, file_name) + file_content = response.read() + response.close() + response.release_conn() + return file_content + + except S3Error as exc: + print(f"Error occurred while retrieving '{file_name}':", exc) + return None def logVCAction(self,user, action): diff --git a/requirements.txt b/requirements.txt index d4ea454..20dfe62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ yarl==1.9.2 supabase==1.0.3 SQLAlchemy==2.0.32 psycopg2==2.9.9 +minio==7.2.8 \ No newline at end of file