File size: 1,175 Bytes
6ce9ced
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()