Update AzureBlobStorageVideo.py

#26
by Shashika-HF - opened
Files changed (1) hide show
  1. AzureBlobStorageVideo.py +25 -3
AzureBlobStorageVideo.py CHANGED
@@ -9,6 +9,22 @@ file_path = r"C:\Users\ASUS\Desktop\UoW\2ND YEAR\SDGP\HuggingFace\Video\producti
9
  file_name = "uploaded_video.mp4"
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def uploadUserVideoToBlobStorage(file_path, file_name):
13
  """Uploads an MP4 video file to the specified Azure Blob Storage container and returns the URL.
14
 
@@ -36,7 +52,7 @@ def uploadUserVideoToBlobStorage(file_path, file_name):
36
  # Open the video file in binary mode for upload
37
  with open(file_path, "rb") as data:
38
  # Upload the video data to the blob
39
- upload_blob_result = blob_client.upload_blob(data)
40
 
41
  # Get the URL for the uploaded blob
42
  blob_url = blob_client.url
@@ -49,9 +65,15 @@ def uploadUserVideoToBlobStorage(file_path, file_name):
49
  raise # Re-raise the exception for further handling
50
 
51
  if __name__ == "__main__":
52
-
53
  # Example usage
54
  uploaded_video_url = uploadUserVideoToBlobStorage(file_path, file_name)
55
- # You can now use the uploaded_video_url for further processing or sharing
 
 
 
 
 
 
 
56
 
57
 
 
9
  file_name = "uploaded_video.mp4"
10
 
11
 
12
+
13
+ def deleteUserVideoFromBlobStorage(container_client,blob_name):
14
+ """Deletes the specified blob from Azure Blob Storage.
15
+
16
+ Args:
17
+ blob_client (BlobClient): The BlobClient object for the blob to delete.
18
+ """
19
+ try:
20
+ # Get the blob client within the function for deletion
21
+ blob_client = container_client.get_blob_client(blob_name)
22
+ blob_client.delete_blob()
23
+ print(f"Video deleted successfully from Azure Blob Storage.")
24
+ except Exception as e:
25
+ print(f"Error deleting video: {e}")
26
+
27
+
28
  def uploadUserVideoToBlobStorage(file_path, file_name):
29
  """Uploads an MP4 video file to the specified Azure Blob Storage container and returns the URL.
30
 
 
52
  # Open the video file in binary mode for upload
53
  with open(file_path, "rb") as data:
54
  # Upload the video data to the blob
55
+ upload_blob_result = blob_client.upload_blob(data, overwrite=True)
56
 
57
  # Get the URL for the uploaded blob
58
  blob_url = blob_client.url
 
65
  raise # Re-raise the exception for further handling
66
 
67
  if __name__ == "__main__":
 
68
  # Example usage
69
  uploaded_video_url = uploadUserVideoToBlobStorage(file_path, file_name)
70
+ # use the uploaded_video_url for further processing or sharing
71
+ # Retrieve container_client from within the upload function
72
+ blob_service_client = BlobServiceClient.from_connection_string(conn_str=connection_string)
73
+ container_client = blob_service_client.get_container_client(container_name)
74
+
75
+ # Pass container_client and file_name to the deletion function
76
+ deleteUserVideoFromBlobStorage(container_client,file_name)
77
+
78
 
79