如何从asp.net web api中删除Azure blob
本文关键字:删除 Azure blob api web asp net | 更新日期: 2023-09-27 18:00:32
将图像从我的web api上传到azure blob存储可以很好地工作,但在尝试删除它们时,我会收到以下错误:"Microsoft.WindowsAzure.Storage.dll中出现类型为"Microsoft.WindowsAzure.StorageException"的异常,但未在用户代码中进行处理
这是我使用的代码:
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Retrieve reference to a blob named "myblob.txt".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob.txt");
// Delete the blob.
blockBlob.Delete();
我尝试使用的代码来自:https://azure.microsoft.com/sv-se/documentation/articles/storage-dotnet-how-to-use-blobs/#delete-斑点
非常感谢任何帮助或意见,谢谢!
您应该确保文件名或容器名正确。两种方法我都用。我相信它对两者都有效。
你能试试下面这行的代码吗?
var result= blockBlob.DeleteIfExists();