Kanyu
Kanyu

Reputation: 43

Not able to delete blob from Azure storage Account - Azure Function (Java)

When I try to delete a blob from an Azure storage account from my Azure Function (Java) the program just hangs on blob.deleteIfExists();

When I perform the same operations on a local storage emulator it runs just fine and deletes the blob from the container.

Here is the code that I am using to delete the blob.

        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(System.getenv("STORAGE"));
        
        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
          
        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.getContainerReference("container-name");
            
        // Retrieve reference to a blob named fileName.
        CloudBlockBlob blob = container.getBlockBlobReference(fileName); 
        context.getLogger().info(blob.getName());

        // Delete the blob.
        blob.deleteIfExists();

The line where I have context.getLogger().info(blob.getName()); works fine and returns the correct blob but blob.deleteIfExists(); is just causing the program to hang.

Upvotes: 1

Views: 1011

Answers (1)

Kanyu
Kanyu

Reputation: 43

It was a permissions issue when testing locally. When deployed to Azure the blob deletion happened as it should.

Upvotes: 1

Related Questions