-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_to_azure_blob.py
48 lines (35 loc) · 1.58 KB
/
connection_to_azure_blob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os, uuid
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
print(os.getcwd())
try:
# print("Azure Blob storage v" + __version__ + " - Python quickstart sample")
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
# print('TRUE 1')
# Create the BlobServiceClient object which will be used to create a container client
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
# print('TRUE 2')
# Create a unique name for the container
container_name = "miroshnychenko"
# print('TRUE 3')
# Create the container
# print('TRUE 3.2')
container_client = blob_service_client.create_container(container_name)
# print('TRUE 4')
except Exception as ex:
print('Exception:')
print(ex)
#print('TRUE 5')
#new_container = blob_service_client.create_container("containerfromblobservice")
#properties = new_container.get_container_properties()
#print('TRUE 6')
# Create a file in local data directory to upload and download
local_path = "./blob-quickstart-v12/data"
local_file_name = "IndianFoodDatasetCSV.csv"
upload_file_path = os.path.join(local_path, local_file_name)
print('FILE EXIST')
# Create a blob client using the local file name as the name for the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)
# Upload the created file
with open(upload_file_path, "rb") as data:
blob_client.upload_blob(data)