如何从ASP.NET Web API删除Azure Blob?

马蒂亚斯

将图像从我的Web api上传到azure blob存储可以正常工作,但是在尝试删除它们时却出现以下错误:“ Microsoft.WindowsAzure.Storage.dll中发生了'Microsoft.WindowsAzure.Storage.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-blobs

任何帮助或输入表示高度赞赏,谢谢!

塞尔达·卡特皮纳尔(Serdar Catalpinar)

您应该确保正确的文件名或容器名。我同时使用这两种方法。我确信这两种方法都可以。

您可以在下面的行中尝试代码吗?

var result= blockBlob.DeleteIfExists();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章