我试图删除虚拟目录中的blob,没有运气。始终返回404错误。
文件网址如下:https://XXX.blob.core.windows.net/YY/pdf/pdf/file.pdf 其中XXX是我的存储帐户,YY是容器。
我试图删除它的全名(pdf / pdf / file.pdf,没有运气。
blockBlob = container.GetBlockBlobReference("pdf/pdf/file.pdf"); //or
blockBlob = container.GetBlockBlobReference("file.pdf");
此外,尝试浏览trhough虚拟文件夹(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
注意:我可以成功删除根目录中的文件(https://XXX.blob.core.windows.net/YY/file.pdf)。
错误:
blockBlob.Delete()' threw an exception of type 'Microsoft.WindowsAzure.Storage.StorageException'
base: {"The remote server returned an error: (404) Not found."}
RequestInformation: {Microsoft.WindowsAzure.Storage.RequestResult}
更新
我设法使用此代码删除:
foreach (var blobItem in container.ListBlobs(useFlatBlobListing: true)) {
if (blobItem.Uri.ToString() == caminho) {
blockBlob.Delete();
return "";
}
}
......但这似乎是一个疯狂的解决方案......:/