Summarize the problem:
I am trying to upload a local folder to Blob Storage using BlobServiceClient with Python. Some of the questions here and here do not work because create_blob_from_path() doesn't work in V12 SDK and I wouldn't want to go back to older version.
What I've tried:
I am using os.walk for local directory but missing the most important part like a function similar to create_blob_from_path().
Sample code:
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, PublicAccess
import os
base_file_path = '/path/to/my/local/directory/'
connect_str = '1q2w3e4r5t6y'
container_name = 'abc'
try:
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
container_name = 'abc' # already created in Azure
container_client = blob_service_client.get_container_client(container_name)
upload_local_file_path = base_file_path + 'csv-summary-output' # input folder path
for root, subdir, local_file in os.walk(upload_local_file_path):
if local_file:
for name in local_file:
dir_part = os.path.relpath(root, upload_local_file_path)
file_path = os.path.join(root, name)
==> missing parts here
except Exception as ex:
print('Exception:')
print(ex)
Any help is much appreciated and I will take a look at Azure Github to see if anything useful there.