Created
October 30, 2020 09:24
-
-
Save skyline75489/3dd6fc3f22434f68e2e1dcb52849cfb0 to your computer and use it in GitHub Desktop.
Upload a local folder using azure.storage.blob==12.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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