Search code examples
azurespring-bootazure-blob-storagespring-boot-starter

Error with Azure Blob Storage Starter API for Spring boot in Java


I have a issue trying to delete a "folder" (blob) from Azure Blob Storage. I have a container and inside that container multiple "folders" (blobs) than contain a big amount of "files" blobs inside.

So, for example, if I have a file called test.pdf inside a blob "folder" called 1234 and I go to search the "file" blob /1234/test.pdf, I'm able to find it, download it or delete it. But if I search for the blob "folder" /1234/ I always get an error saying that the blob doesn't exist "404 BlobNotFound The specified blob does not exist".

This is the code I'm using:

BlobURL blobURL = containerUrl.createBlobURL(folderName+"/"+fileName);
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); //It Works

BlobURL blobURL = containerUrl.createBlobURL(folderName+"/");
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); // Did not works

BlobURL blobURL = containerUrl.createBlobURL(folderName);
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); // Did not works

Any advice? Thanks in advance!


Solution

  • If you are using createBlobUrl it should be a valid url of the blob which refers to the actual blob. If you want to access all the blobs inside a contianer, you should use

    var blobList= container.ListBlobs(prefix: "folderName/", useFlatBlobListing: true);