Skip to content

Instantly share code, notes, and snippets.

@skyline75489
Created October 30, 2020 09:24
Show Gist options
  • Save skyline75489/3dd6fc3f22434f68e2e1dcb52849cfb0 to your computer and use it in GitHub Desktop.
Save skyline75489/3dd6fc3f22434f68e2e1dcb52849cfb0 to your computer and use it in GitHub Desktop.
Upload a local folder using azure.storage.blob==12.5
import os, mimetypes, sys, uuid
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, ContentSettings
connect_str = "CONNECTION_STRING"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
def upload_file(f):
container_name = "CONTAINER"
local_path = f
local_file_name = f
upload_file_path = f
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
content_type = mimetypes.guess_type(local_path)[0]
with open(upload_file_path, "rb") as data:
blob_client.upload_blob(data, overwrite=True, content_settings=ContentSettings(content_type=content_type))
if __name__ == '__main__':
folder = sys.argv[1]
for root, dirs, files in os.walk(folder, topdown=True):
for name in files:
f = os.path.join(root, name)
print('Uploading' + f)
upload_file(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment