Member-only story

Upload files to Azure Blob Storage (Python)

Park Sehun
2 min readMay 1, 2023

Ref: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python?tabs=managed-identity%2Croles-azure-portal%2Csign-in-azure-cli

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, _…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response