I want to get a list of empty containers in a storage account using Java.
Here is my initial approach to check if container does not have any blobs:
var defaultCredential = new DefaultAzureCredentialBuilder().build();
var containerClient = new BlobContainerClientBuilder()
.endpoint("https://storageaccount.blob.core.windows.net/testcontainer/")
.credential(defaultCredential)
.buildClient();
var isEmpty = containerClient.listBlobs().stream().findAny().isEmpty();
Unfortunately, this simple approach does not work and throws "Signature did not match" exception
com.azure.storage.blob.models.BlobStorageException: If you are using a StorageSharedKeyCredential, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate method call. If you are using a SAS token, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate generateSas method call. Please remember to disable 'Azure-Storage-Log-String-To-Sign' before going to production as this string can potentially contain PII. Status code 403, "
AuthorizationPermissionMismatch
This request is not authorized to perform this operation using this permission.
Credentials are fine, and even more
var exists = containerClient.exists();
works and returns true.
What is wrong with the .listBlobs().stream().findAny().isEmpty()
call?