mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 12:45:59 +08:00
Fix: google storage init with sa and download (#5054)
This commit is contained in:
parent
db976a1f74
commit
3f18369ad2
@ -1,5 +1,6 @@
|
|||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
@ -20,7 +21,9 @@ class GoogleStorage(BaseStorage):
|
|||||||
# if service_account_json_str is empty, use Application Default Credentials
|
# if service_account_json_str is empty, use Application Default Credentials
|
||||||
if service_account_json_str:
|
if service_account_json_str:
|
||||||
service_account_json = base64.b64decode(service_account_json_str).decode('utf-8')
|
service_account_json = base64.b64decode(service_account_json_str).decode('utf-8')
|
||||||
self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_json)
|
# convert str to object
|
||||||
|
service_account_obj = json.loads(service_account_json)
|
||||||
|
self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_obj)
|
||||||
else:
|
else:
|
||||||
self.client = GoogleCloudStorage.Client()
|
self.client = GoogleCloudStorage.Client()
|
||||||
|
|
||||||
@ -48,9 +51,7 @@ class GoogleStorage(BaseStorage):
|
|||||||
def download(self, filename, target_filepath):
|
def download(self, filename, target_filepath):
|
||||||
bucket = self.client.get_bucket(self.bucket_name)
|
bucket = self.client.get_bucket(self.bucket_name)
|
||||||
blob = bucket.get_blob(filename)
|
blob = bucket.get_blob(filename)
|
||||||
with open(target_filepath, "wb") as my_blob:
|
blob.download_to_filename(target_filepath)
|
||||||
blob_data = blob.download_blob()
|
|
||||||
blob_data.readinto(my_blob)
|
|
||||||
|
|
||||||
def exists(self, filename):
|
def exists(self, filename):
|
||||||
bucket = self.client.get_bucket(self.bucket_name)
|
bucket = self.client.get_bucket(self.bucket_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user