Here is a script to upload files to azure storage using the latest SDK.
#!/usr/bin/env python
from azure.storage.blob import BlobClient
import os
import uuid
storage_access_key = "storage_account_access_key"
storage_name = "storage_account_name"
CNTR_STORAGE_NAME = "container_name"
con_str = f'DefaultEndpointsProtocol=https;AccountName={storage_name};AccountKey={storage_access_key}'
# Create a local directory to hold blob data if the path not exist
local_path = "./data"
if not os.path.exists(local_path):
os.mkdir(local_path)
# Create a file in the local data directory to upload and download
local_file_name = str(uuid.uuid4()) + ".txt"
upload_file_path = os.path.join(local_path, local_file_name)
# Write text to the file
file = open(upload_file_path, 'w')
file.write("Hello, World!")
file.close()
blob = BlobClient.from_connection_string(conn_str=con_str, container_name=CNTR_STORAGE_NAME, blob_name=local_file_name)
with open(upload_file_path, "rb") as data:
blob.upload_blob(data)
Comments
Post a Comment