diff --git a/code/backend/batch/utilities/helpers/AzureBlobStorageClient.py b/code/backend/batch/utilities/helpers/AzureBlobStorageClient.py index ea1fb4dce..10dc1391c 100644 --- a/code/backend/batch/utilities/helpers/AzureBlobStorageClient.py +++ b/code/backend/batch/utilities/helpers/AzureBlobStorageClient.py @@ -168,7 +168,21 @@ def delete_file(self, file_name): blob_client = self.blob_service_client.get_blob_client( container=self.container_name, blob=file_name ) - blob_client.delete_blob() + if blob_client.exists(): + blob_client.delete_blob() + + def delete_files(self, files): + """ + Deletes files from the Azure Blob Storage container. + + Args: + files (list[str]): The names of the files to delete. + + Returns: + None + """ + for filename, ids in files.items(): + self.delete_file(filename) def get_all_files(self): # Get all files in the container from Azure Blob Storage diff --git a/code/backend/pages/03_Delete_Data.py b/code/backend/pages/03_Delete_Data.py index 6b71b547c..f9391b03b 100644 --- a/code/backend/pages/03_Delete_Data.py +++ b/code/backend/pages/03_Delete_Data.py @@ -5,6 +5,7 @@ import logging from batch.utilities.helpers.EnvHelper import EnvHelper from batch.utilities.search.Search import Search +from batch.utilities.helpers.AzureBlobStorageClient import AzureBlobStorageClient sys.path.append(os.path.join(os.path.dirname(__file__), "..")) env_helper: EnvHelper = EnvHelper() @@ -65,6 +66,9 @@ files_to_delete = search_handler.delete_files( selected_files, ) + # Delete from Storage + blob_client = AzureBlobStorageClient() + blob_client.delete_files(selected_files) if len(files_to_delete) > 0: st.success("Deleted files: " + str(files_to_delete))