【问题标题】:Cannot delete the blob that triggers an Azure Function Blob Input Binding无法删除触发 Azure 函数 Blob 输入绑定的 Blob
【发布时间】:2018-10-21 23:53:40
【问题描述】:

这是这个问题的后续问题:

How to delete a blob using Azure Functions?

当 blob 触发我的 Azure 函数时,我需要在其处理完成后将其删除。否则,我最终会在容器中产生许多 blob。

当我运行以下代码时:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("process");
var blockBlob = container.GetBlockBlobReference($"process/in/{name}"); // ==> This was the problem. See the answer for more info. 
bool deleted = blockBlob.DeleteIfExists();

blockBlob.DeleteIfExists() 方法总是返回 false,它从不删除 blob。

我的猜测是,该 blob 以某种方式被函数执行锁定,因为它刚刚触发了它。

[更新 1]

...

[更新 2]

非常感谢@Jerry Liu,这个问题与 Azure Fundctions 无关。

诀窍在于,当调用者错误地发送错误路径时,blockBlob.DeleteIfExists() 返回 false。

更好的方法是使用“blockBlob.Delete”并找出实际问题。

有关详细信息,请参阅 DeleteIfExists 源代码。

https://github.com/Azure/azure-storage-net/blob/master/Lib/ClassLibraryCommon/Blob/CloudBlob.cs#L1993

另一个相关问题: Azure CloudBlockBlob.DeleteIfExists() - Does false always mean the blob doesn't exist?

【问题讨论】:

  • 相同的代码删除了我这边的 blob,这可能与您的 blob 的处理方式有关。你能在删除之前提供一些上下文 sn-p 吗?
  • @JerryLiu:感谢您对此进行调查。这是重现问题的代码。

标签: c# azure azure-storage azure-functions azure-blob-storage


【解决方案1】:

问题出在这一行

var blockBlob = container.GetBlockBlobReference($"process/in/{name}");

blob 名称应该是$"in/{name}",因为我们根据GetContainerReference 中已经获得的特定容器调用GetBlockBlobReference

重复导致存储无法找到 blob。我们可能会对没有相关的提示/异常感到困惑,因为DeleteIfExists 在 blob 不存在时也会返回 false。

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2021-12-31
    • 1970-01-01
    • 2020-06-09
    • 2019-09-14
    • 1970-01-01
    相关资源
    最近更新 更多