Buy Me a Coffee? Your support is much appreciated!



demo.py

import os
from azure.storage.blob import BlobServiceClient # pip install azure-storage-blob
from azure.core.exceptions import ResourceExistsError

storage_connection_string = '<connection string>'
blob_service_client = BlobServiceClient.from_connection_string(storage_connection_string)

container_id = '<container id>'
blob_service_client.get_container_client(container_id)

overwrite = False
target_directory = os.path.join(os.getcwd(), 'dbt')

for folder in os.walk(target_directory):
    for file in folder[-1]:
        try:
            blob_path = os.path.join(folder[0].replace(os.getcwd() + '\\', ''), file)
            blob_obj = blob_service_client.get_blob_client(container=container_id, blob=blob_path)
            
            with open(os.path.join(folder[0], file), mode='rb') as file_data:
                blob_obj.upload_blob(file_data, overwrite=overwrite)
        except ResourceExistsError:
            print('Blob "{0}" already exists'.format(blob_path))
            print()
            continue