如何从 asp.net web api 中删除 Azure blob?

How to delete Azure blob from asp.net web api?

从我的网站 api 上传图像到 Azure blob 存储工作正常,尽管在尝试删除它们时我收到以下错误: "An exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code"

这是我使用的代码:

// 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-blobs

非常感谢任何帮助或意见,谢谢!

您应该确保文件名或容器名正确。 我两者都用 methods.I 我确定它在两者中都有效。

你能试试下面这行的代码吗?

var result= blockBlob.DeleteIfExists();