2015-06-30 52 views
1

将图像从我的web api上传到azure blob存储工作正常,尽管试图删除它们时出现以下错误: “Microsoft.WindowsAzure.Storage中发生了类型为”Microsoft.WindowsAzure.Storage.StorageException“的异常。 DLL而不是在用户代码”如何从asp.net web api删除Azure blob?

这是代码即时通讯使用的处理:

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

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

+0

也许你应该看看例外情况并尝试解释它。发布结果。 – usr

+0

你可以给我们完整的堆栈跟踪吗? – ramiramilu

回答

2

您应该确保正确的文件名或容器名称。 我使用这两种方法。我相信它在两个方面都有效。

你可以尝试下面的代码行吗?

var result= blockBlob.DeleteIfExists();