Created
March 22, 2018 16:56
-
-
Save kevinhillinger/e4e687a740ce81e0266aeec38ed9f748 to your computer and use it in GitHub Desktop.
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, sys, uuid, time | |
from azure.storage.blob import BlockBlobService, PublicAccess | |
CONTAINER_NAME = '<container name>' | |
service = BlockBlobService(account_name='<account name', account_key='<your key>') | |
try: | |
service.create_container(container_name = CONTAINER_NAME) | |
except: | |
print('container exists') | |
def upload_file(): | |
id = str(uuid.uuid4()) | |
local_path = os.path.expanduser("~/Downloads") | |
file_path = "blob_" + id + ".txt" | |
full_file_path = os.path.join(local_path, file_path) | |
file = open(full_file_path, 'w') | |
file.write("Id: " + id) | |
file.write("\nTimestamp: " + str(time.time())) | |
file.close() | |
print("Temp file: " + full_file_path) | |
print("\nUploading to storage as " + file_path) | |
service.create_blob_from_path(container_name=CONTAINER_NAME, blob_name = file_path, file_path = full_file_path) | |
os.remove(full_file_path) | |
if __name__ == '__main__': | |
sys.stdout.write("Press any key to begin sending files to blob storage container '" + CONTAINER_NAME + "'") | |
sys.stdout.flush() | |
exit_loop = False | |
while not exit_loop: | |
number_of_files_input = input("enter number of files to send to blob storage or 'q' to quit: ") | |
if (number_of_files_input == 'q'): | |
exit_loop = True | |
else: | |
number_of_files = int(number_of_files_input) | |
for i in range(0, number_of_files): | |
upload_file() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment