Spaces:
Runtime error
Runtime error
Update AzureBlobStorageVideo.py
Browse files- 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(
|
| 15 |
-
"""
|
|
|
|
| 16 |
|
| 17 |
Args:
|
| 18 |
-
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
-
print(f
|
| 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 |
-
|
| 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)
|
|
|