BlobBatchClient.deleteBlobs doesn`t actually delete the blobs.

Kosala De Silva 41 Reputation points
2020-09-08T10:10:34.813+00:00

I am using azure-storage-blob-batch artifact with 12.6 version.
I am trying to delete multiple blobs using batch delete. but it doesnt seems to work. bellow is my code sample.
Can anyone tell me what am I doing wrong here?

   private static void removeBlobs() {

      final BlobServiceClient blobServiceClient =
              new BlobServiceClientBuilder().connectionString(parameters.getConnectionString()).buildClient();
      final BlobContainerClient releaseContainer =
              blobServiceClient.getBlobContainerClient("container");
      final ListBlobsOptions listBlobsOptions =
              new ListBlobsOptions().setPrefix("path/subpath");
      final BlobBatchClient batchClient = new BlobBatchClientBuilder(blobServiceClient).buildClient();
      final List<String> blobUrls = new ArrayList<>();

      for (BlobItem blobItem : releaseContainer.listBlobs(listBlobsOptions, Duration.ofSeconds(60))) {
         final BlobClient sourceBlobClient = releaseContainer.getBlobClient(blobItem.getName());
         blobUrls.add(sourceBlobClient.getBlobUrl());
      }
      batchClient.deleteBlobs(blobUrls, DeleteSnapshotsOptionType.INCLUDE);
   }
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
{count} votes

1 answer

Sort by: Most helpful
  1. Sumarigo-MSFT 47,506 Reputation points Microsoft Employee Moderator
    2020-09-14T09:08:49.727+00:00

    @Kosala De Silva Adding additional information to Derek response:

    blobBatchClient.deleteBlobs(blobUrls, DeleteSnapshotsOptionType.INCLUDE).forEach(response ->
    System.out.printf("Deleting blob with URL %s completed with status code %d%n",
    response.getRequest().getUrl(), response.getStatusCode()));

    For more information refer here for Advanced Batching: https://learn.microsoft.com/en-us/java/api/overview/azure/storage-blob-batch-readme?view=azure-java-stable

    Are you getting any error message or error code, If so can you please share the screenshot?

    See here for BlobBatchClient class BlobBatchClient.deleteBlobs Method and BlobBatchClient.DeleteBlobs(IEnumerable<Uri>, DeleteSnapshotsOption, CancellationToken) Method

    Additional information: You can refer to this SO thread
    https://azuresdkdocs.blob.core.windows.net/$web/dotnet/Azure.Storage.Blobs.Batch/12.0.0-preview.5/api/index.html

    Additional information: For your reference you can use the REST API to Delete Blob and similar issue on GitHub forum.

    If you still find any difficulties, please let us know, We would like to work closer on this issue. Looking forward for your reply.

    Hope this helps! Kindly let us know if the above helps or you need further assistance on this issue.

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    Please don’t forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.