-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy path850968-Gurrala_Nohar.py
57 lines (24 loc) · 1.32 KB
/
850968-Gurrala_Nohar.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
49
50
51
52
53
54
55
56
57
import os
import uuid
import sys
from azure.storage.blob import BlockBlobService, PublicAccess
# Block blobs let you upload large blobs efficiently
blob_service_client = BlockBlobService(account_name='accountname', account_key='accountkey')
# To create a container.
container_name = 'DemoContainer'
blob_service_client.create_container(container_name)
# Set the permission so the blobs are public.
blob_service_client.set_container_acl(container_name, public_access=PublicAccess.Container)
# Create Sample folder if it not exists, and create a file in folder Sample to test the upload and download.
local_path = os.path.expanduser("~/Sample")
# Check whether Directory exists or not. If not then Create new directory
if not os.path.exists(local_path):
s.makedirs(os.path.expanduser("~/Sample"))
# Creating a file name
local_file_name = "QuickStart_" + str(uuid.uuid4()) + ".txt"
# Creating a Present working directory of file, including the file name
full_path_to_file = os.path.join(local_path, local_file_name)
# Upload the created file, use local_file_name for the blob name
blob_service_client.create_blob_from_path(container_name, local_file_name, full_path_to_file)
# List the blobs in the container
generator = blob_service_client.list_blobs(container_name)