Spaces:
Running
Running
Commit
·
f1dd29d
1
Parent(s):
12d8e4b
fix: google credentials issue
Browse files
src/services/google_cloud_image_upload.py
CHANGED
@@ -1,11 +1,17 @@
|
|
1 |
from google.cloud import storage
|
2 |
from PIL import Image
|
3 |
-
from dotenv import load_dotenv
|
4 |
import os
|
5 |
import uuid
|
6 |
import tempfile
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
class GoogleCloudImageUploadService:
|
11 |
BUCKET_NAME = "picchat-assets"
|
@@ -14,7 +20,9 @@ class GoogleCloudImageUploadService:
|
|
14 |
def __init__(self):
|
15 |
# Using API key here as per your original code. Note that for production,
|
16 |
# service account credentials are generally recommended.
|
17 |
-
|
|
|
|
|
18 |
|
19 |
def upload_image_to_gcs(self, source_file_name):
|
20 |
"""
|
|
|
1 |
from google.cloud import storage
|
2 |
from PIL import Image
|
|
|
3 |
import os
|
4 |
import uuid
|
5 |
import tempfile
|
6 |
|
7 |
+
def get_credentials():
|
8 |
+
credentials_json_string = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
|
9 |
+
|
10 |
+
# create a temp file with the credentials
|
11 |
+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp_file:
|
12 |
+
temp_file.write(credentials_json_string)
|
13 |
+
temp_file_path = temp_file.name
|
14 |
+
return temp_file_path
|
15 |
|
16 |
class GoogleCloudImageUploadService:
|
17 |
BUCKET_NAME = "picchat-assets"
|
|
|
20 |
def __init__(self):
|
21 |
# Using API key here as per your original code. Note that for production,
|
22 |
# service account credentials are generally recommended.
|
23 |
+
# get credentials from env
|
24 |
+
credentials_json = get_credentials()
|
25 |
+
self.storage_client = storage.Client.from_service_account_json(credentials_json)
|
26 |
|
27 |
def upload_image_to_gcs(self, source_file_name):
|
28 |
"""
|