Spaces:
Sleeping
Sleeping
import os | |
from azure.storage.blob import BlobServiceClient | |
from dotenv import load_dotenv | |
load_dotenv() | |
# Initialize Azure Blob Service Clients | |
blob_service_client = BlobServiceClient.from_connection_string(os.environ["AZURE_STORAGE_CONNECTION_STRING"]) | |
# Function to upload file to Azure Storage | |
def upload_to_azure(blob_service_client, container_name, file, file_name): | |
container_client = blob_service_client.get_container_client(container_name) | |
container_client.upload_blob(name=file_name, data=file, overwrite=True) | |
# Function to download file from Azure Storage | |
def download_from_azure(blob_service_client, container_name, file_name): | |
container_client = blob_service_client.get_container_client(container_name) | |
blob_client = container_client.get_blob_client(blob=file_name) | |
file_content = blob_client.download_blob().readall() | |
return file_content | |
# Function to delete file from Azure Storage | |
def delete_from_azure(blob_service_client, container_name, file_name): | |
container_client = blob_service_client.get_container_client(container_name) | |
blob_client = container_client.get_blob_client(blob=file_name) | |
blob_client.delete_blob() | |