c# - 如何从 asp.net web api 删除 Azure blob?

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

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

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

最佳答案

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

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

var result= blockBlob.DeleteIfExists();

关于c# - 如何从 asp.net web api 删除 Azure blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31136723/

相关文章:

c# - 查找单个类的所有依赖项

c# - 以编程方式用于 Grid 的 ImageBrush

c# - 如何在GridView EditTemplate中设置DropDownList的SelectedValue

asp.net - OWIN AuthorizeEndpoint 的 redirect_uri 与 web api 的 uri 不同

c# - 反序列化web api项目中的json数组

angular - Windows 身份验证在 Microsoft Edge 浏览器中不适用于 Angular 2 应用程序

c# - Azure Blob 容器名称可以有多长?

c# - 获取机器上的所有 IP 地址

azure - 如何找到共享访问 token 已过期的 bloburl?

Azure-Bicep:如何将 blob 容器添加到存储帐户