C# 删除虚拟目录中的blob
我正试图删除虚拟目录中的一个blob,但运气不好。始终返回404错误 文件url如下所示: 其中XXX是我的存储帐户,YY是一个容器 我试图删除它的全名(pdf/pdf/file.pdf,运气不好)C# 删除虚拟目录中的blob,c#,azure,azure-storage,azure-storage-blobs,C#,Azure,Azure Storage,Azure Storage Blobs,我正试图删除虚拟目录中的一个blob,但运气不好。始终返回404错误 文件url如下所示: 其中XXX是我的存储帐户,YY是一个容器 我试图删除它的全名(pdf/pdf/file.pdf,运气不好) blockBlob = container.GetBlockBlobReference("pdf/pdf/file.pdf"); //or blockBlob = container.GetBlockBlobReference("file.pdf"); 此外,我还尝试浏览虚拟文件夹(GetDire
blockBlob = container.GetBlockBlobReference("pdf/pdf/file.pdf"); //or
blockBlob = container.GetBlockBlobReference("file.pdf");
此外,我还尝试浏览虚拟文件夹(GetDirectoryReference)并在到达时删除该文件,但也没有成功
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("YY");
CloudBlockBlob blockBlob;
string sBlob = fullUrl.Substring(fullUrl.IndexOf("YY/") + ("YY/").Length);
string[] sDirs = sBlob.Split(new Char[] { '/' });
if (sDirs.Length > 0)
{
CloudBlobDirectory dir = container.GetDirectoryReference(sDirs[0]);
if (sDirs.Length > 2)
{
for (int i = 1; i < sDirs.Length - 2; i++)
{
dir = dir.GetDirectoryReference(sDirs[i]);
}
}
blockBlob = dir.GetBlockBlobReference(sDirs[sDirs.Length - 1]);
}
else
{
blockBlob = container.GetBlockBlobReference(sBlob);
}
blockBlob.Delete(); //when debugging, I can see blockBlob properties here
更新:
我使用以下代码成功删除:
foreach (var blobItem in container.ListBlobs(useFlatBlobListing: true)) {
if (blobItem.Uri.ToString() == caminho) {
blockBlob.Delete();
return "";
}
}
…但这似乎是一个疯狂的解决方案…:/您能检查并粘贴存储服务返回的准确错误吗?@astaykov我刚刚更新了原始帖子…谢谢您100%确定此blob仍然存在吗?当您使用
GetBlobreReferenceFromServer
@plentysmart刚刚尝试blockBlob=(CloudBlockBlob)blobClient.GetBlobReferenceFromServer(blockBlob.Uri);实际上,我得到了404错误。但是在WA管理门户中,我可以看到这个blob,它的Uri完全相同!当您列出blob-容器。ListBlob(useFlatBlobListing:true);
?
foreach (var blobItem in container.ListBlobs(useFlatBlobListing: true)) {
if (blobItem.Uri.ToString() == caminho) {
blockBlob.Delete();
return "";
}
}