【发布时间】:2016-06-13 00:16:58
【问题描述】:
我正在尝试使用 Java Azure Storage Library 4.0.0 删除 Azure 存储容器中的一些 blob,如 here 所述。看起来这应该是一件容易的事,所以我假设我做错了什么,因为下面的代码不会删除任何东西。容器中有 4 个 blob。
String connectionString = String.format(
"DefaultEndpointsProtocol=https;" +
"AccountName=%s;" +
"AccountKey=%s", accountName, accountKey);
CloudStorageAccount account =
CloudStorageAccount.parse(connectionString);
CloudBlobClient client = account.createCloudBlobClient();
CloudBlobContainer container =
client.getContainerReference("myContainer");
// This loop iterates 4 times, as expected
for (ListBlobItem item : container.listBlobs("prefix/", true)) {
CloudBlockBlob blob = container.
getBlockBlobReference(item.getUri().toString());
if (blob.deleteIfExists()) {
// never hits
}
}
没有抛出异常,但 blob 仍然存在。当我调用 delete() 而不是 deleteIfExists() 时,我得到一个 StorageException:“指定的 blob 不存在。”
【问题讨论】:
标签: java azure azure-blob-storage