这是此问题的后续问题:
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 源代码。
另一个相关问题: Azure CloudBlockBlob.DeleteIfExists() - Does false always mean the blob doesn't exist?
最佳答案
问题就在这一行
var blockBlob = container.GetBlockBlobReference($"process/in/{name}");
blob 名称应为 $"in/{name}"
因为我们打电话GetBlockBlobReference
基于我们已经在 GetContainerReference
中获得的特定容器.
重复导致存储无法找到 blob。我们可能会对没有相关的提示/异常感到困惑,因为DeleteIfExists
当 blob 不存在时也返回 false。
关于c# - 无法删除触发 Azure Function Blob 输入绑定(bind)的 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52885397/