Files changed (1) hide show
  1. AzureBlobStorageAudio.py +16 -8
AzureBlobStorageAudio.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from azure.storage.blob import BlobServiceClient
2
 
3
  # Replace placeholders with your actual credentials
@@ -9,13 +10,16 @@ container_name = "useruploadhuggingfaceaudio" # Update container name for audio
9
  file_path = r"C:\Users\ASUS\Desktop\UoW\2ND YEAR\SDGP\AUDIO\edit\3_second_audio.flac" # Update path to your MP3 file
10
  file_name = "uploaded_audio.mp3"
11
 
12
- def deleteUserAudioFromBlobStorage(blob_client):
 
13
  """Deletes the specified blob from Azure Blob Storage.
14
 
15
  Args:
16
  blob_client (BlobClient): The BlobClient object for the blob to delete.
17
  """
18
  try:
 
 
19
  blob_client.delete_blob()
20
  print(f"Audio deleted successfully from Azure Blob Storage.")
21
  except Exception as e:
@@ -45,19 +49,18 @@ def uploadUserAudioToBlobStorage(file_path, file_name):
45
  # Create the blob client with the specified file name
46
  blob_client = container_client.get_blob_client(file_name)
47
 
 
48
  # Open the audio file in binary mode for upload
49
  with open(file_path, "rb") as data:
50
- # Upload the audio data to the blob
51
- upload_blob_result = blob_client.upload_blob(data)
52
 
53
- # Get the BlobClient object for deleting process
54
- blob_client = container_client.get_blob_client(file_name)
55
 
56
  # Get the URL for the uploaded blob
57
  blob_url = blob_client.url
58
 
59
  print(f"Audio '{file_name}' uploaded successfully. URL: {blob_url}")
60
- return blob_url
61
 
62
  except FileNotFoundError as e:
63
  print(f"Error: File not found at {file_path}.")
@@ -68,5 +71,10 @@ if __name__ == "__main__":
68
  # Example usage
69
  uploaded_audio_url = uploadUserAudioToBlobStorage(file_path, file_name)
70
  # use the uploaded_audio_url for further processing or sharing
71
- # receive the enhanced video:
72
- deleteUserAudioFromBlobStorage(blob_client)
 
 
 
 
 
 
1
+
2
  from azure.storage.blob import BlobServiceClient
3
 
4
  # Replace placeholders with your actual credentials
 
10
  file_path = r"C:\Users\ASUS\Desktop\UoW\2ND YEAR\SDGP\AUDIO\edit\3_second_audio.flac" # Update path to your MP3 file
11
  file_name = "uploaded_audio.mp3"
12
 
13
+
14
+ def deleteUserAudioFromBlobStorage(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"Audio deleted successfully from Azure Blob Storage.")
25
  except Exception as e:
 
49
  # Create the blob client with the specified file name
50
  blob_client = container_client.get_blob_client(file_name)
51
 
52
+
53
  # Open the audio file in binary mode for upload
54
  with open(file_path, "rb") as data:
55
+ # Upload the audio data to the blob allowing overwrites
56
+ upload_blob_result = blob_client.upload_blob(data, overwrite=True)
57
 
 
 
58
 
59
  # Get the URL for the uploaded blob
60
  blob_url = blob_client.url
61
 
62
  print(f"Audio '{file_name}' uploaded successfully. URL: {blob_url}")
63
+ return blob_url # Only return the URL
64
 
65
  except FileNotFoundError as e:
66
  print(f"Error: File not found at {file_path}.")
 
71
  # Example usage
72
  uploaded_audio_url = uploadUserAudioToBlobStorage(file_path, file_name)
73
  # use the uploaded_audio_url for further processing or sharing
74
+
75
+ # Retrieve container_client from within the upload function
76
+ blob_service_client = BlobServiceClient.from_connection_string(conn_str=connection_string)
77
+ container_client = blob_service_client.get_container_client(container_name)
78
+
79
+ # Pass container_client and file_name to the deletion function
80
+ deleteUserAudioFromBlobStorage(container_client, file_name)