【问题标题】:How to delete Azure blob from asp.net web api?如何从 asp.net web api 中删除 Azure blob?
【发布时间】:2015-09-17 03:48:15
【问题描述】:

将图像从我的 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

非常感谢任何帮助或输入,谢谢!

【问题讨论】:

  • 也许您应该查看异常并尝试解释它。发布结果。
  • 你能给我们完整的堆栈跟踪吗?

标签: c# asp.net-web-api azure-blob-storage


【解决方案1】:

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

你能试试下面的代码吗?

var result= blockBlob.DeleteIfExists();

【讨论】:

    猜你喜欢
    • 2017-08-22
    • 2020-04-09
    • 2018-11-21
    • 1970-01-01
    • 2013-07-09
    • 2020-06-28
    • 2019-06-27
    • 2013-07-14
    • 1970-01-01
    相关资源
    最近更新 更多