Files
encoach_backend/helper/firebase_helper.py
Cristiano Ferreira ca6094c3e7 Add question db insert.
2023-08-24 21:28:59 +01:00

27 lines
948 B
Python

from google.cloud import storage
def download_firebase_file(bucket_name, source_blob_name, destination_file_name):
# Downloads a file from Firebase Storage.
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print(f"File downloaded to {destination_file_name}")
return destination_file_name
def upload_file_firebase(bucket_name, destination_blob_name, source_file_name):
# Uploads a file to Firebase Storage.
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
try:
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print(f"File uploaded to {destination_blob_name}")
return True
except Exception as e:
print("Error uploading file to Google Cloud Storage:", e)
return False