Member-only story
Upload files to Azure Blob Storage (Python)
2 min readMay 1, 2023
When you use customised code to upload the files to Azure Blob storage, you will use Azure SDK.
This is the demo to upload files in the different folders on your laptop.
Before coding, you will need to import Azure SDK which is azure.storage.blob. In this demo, I will use the key to access it, but if you need IAM to log in, then you will need other libraries. (from azure.identity import DefaultAzureCredential)
from azure.storage.blob import BlobServiceClient
import os
# Set the connection string to your Azure Blob Storage account
connection_string = "DefaultEndpointsProtocol=https;AccountName=<Account Name>;AccountKey=<Account Key>;EndpointSuffix=core.windows.net"
# Set the name of the container where you want to upload the files
local_folder_path = "/Users/sehun/Downloads/test"
container_name = "testcontainer"
# Set the local paths to the folders containing the files you want to upload
local_folder_paths = [local_folder_path]
# Create a BlobServiceClient object
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
# Create a ContainerClient object
container_client = blob_service_client.get_container_client(container_name)
# Loop through all the local folders
for local_folder_path in local_folder_paths:
# Loop through all the files in the local folder
for root, _…