Shashika-HF commited on
Commit
40fa580
Β·
verified Β·
1 Parent(s): 8559a47

Update AzureBlobStorageVideo.py

Browse files
Files changed (1) hide show
  1. AzureBlobStorageVideo.py +21 -11
AzureBlobStorageVideo.py CHANGED
@@ -8,22 +8,33 @@ connection_string = f"DefaultEndpointsProtocol=https;AccountName={storage_accoun
8
  container_name = "useruploadhuggingfacevideo"
9
  #file_path = r"C:\Users\isuru\Documents\IIT University\Modules\Year 2 - Semester 2\SDGP\HapticAudio SE09 Local Repo\gradio-env\HapticsProject\video\WIND ANIMATION.mp4"
10
  #file_name = "wind_video.mp4"
 
11
 
12
 
13
 
14
- def deleteUserVideoFromBlobStorage(container_client,blob_name):
15
- """Deletes the specified blob from Azure Blob Storage.
 
16
 
17
  Args:
18
- blob_client (BlobClient): The BlobClient object for the blob to delete.
19
  """
20
  try:
21
- # Get the blob client within the function for deletion
22
- blob_client = container_client.get_blob_client(blob_name)
23
- blob_client.delete_blob()
24
- print(f"Video deleted successfully from Azure Blob Storage.")
 
 
 
 
 
 
 
 
 
25
  except Exception as e:
26
- print(f"Error deleting video: {e}")
27
 
28
 
29
  def uploadUserVideoToBlobStorage(file_path, file_name):
@@ -93,6 +104,5 @@ if __name__ == "__main__":
93
  # Retrieve container_client from within the upload function
94
  blob_service_client = BlobServiceClient.from_connection_string(conn_str=connection_string)
95
  container_client = blob_service_client.get_container_client(container_name)
96
-
97
- # Pass container_client and file_name to the deletion function
98
- deleteUserVideoFromBlobStorage(container_client,file_name)
 
8
  container_name = "useruploadhuggingfacevideo"
9
  #file_path = r"C:\Users\isuru\Documents\IIT University\Modules\Year 2 - Semester 2\SDGP\HapticAudio SE09 Local Repo\gradio-env\HapticsProject\video\WIND ANIMATION.mp4"
10
  #file_name = "wind_video.mp4"
11
+ target_container_id = 'useruploadhuggingfacevideo'
12
 
13
 
14
 
15
+ def deleteUserVideoFromBlobStorage(container_id: str) -> None:
16
+ """
17
+ Deletes all blobs within a specified Azure Blob Storage container.
18
 
19
  Args:
20
+ container_id (str): The ID of the container to delete.
21
  """
22
  try:
23
+ # Establish connection using your storage connection string (replace with yours)
24
+ storage_connection_string = '<connection string>'
25
+ blob_service_client = azure.storage.blob.BlobServiceClient.from_connection_string(storage_connection_string)
26
+
27
+ # Get container client
28
+ container_client = blob_service_client.get_container_client(container_id)
29
+
30
+ # Delete all blobs in the container (iterator for large datasets)
31
+ blobs = container_client.list_blobs()
32
+ for blob in blobs:
33
+ container_client.delete_blob(blob.name)
34
+ print(f'Container "{container_id}" emptied successfully.')
35
+
36
  except Exception as e:
37
+ print(f'Error deleting blobs: {e}')
38
 
39
 
40
  def uploadUserVideoToBlobStorage(file_path, file_name):
 
104
  # Retrieve container_client from within the upload function
105
  blob_service_client = BlobServiceClient.from_connection_string(conn_str=connection_string)
106
  container_client = blob_service_client.get_container_client(container_name)
107
+ target_container_id = 'useruploadhuggingfacevideo'
108
+ deleteUserVideoFromBlobStorage(target_container_id)