gpt4 book ai didi

c# - 仅当 Blob 存在时才获取 Azure Blob 元数据

转载 作者:行者123 更新时间:2023-12-02 07:07:10 32 4
gpt4 key购买 nike

我需要获取 Azure blob 的元数据(如果存在),并且希望通过最少的 REST 调用(通过存储 SDK 到存储服务)来实现此目的

我知道我可以做类似的事情

  • CloudBlockBlob.ExistsAsync() 然后
  • CloudBlockBlob.FetchAttributesAsync()(如果 blob 存在)

我尝试将这两个调用合并为一个

  • CloudBlockBlob.FetchAttributesAsync(AccessCondition.GenerateIfExistsCondition(),new BlobRequestOptions(), new OperationContext());

有关“AccessCondition.GenerateIfExistsCondition()”的文档' 说 -

Constructs an access condition such that an operation will be performed only if the resource exists.

但它仍然失败,并显示 404 未找到。

你知道我想要实现的目标是否可能以及我可能做错了什么吗?

最佳答案

查看该操作的文档:https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties .

这基本上是对 blob 的 HEAD 请求,并且没有提及 header 的 If-Match 等。

所以我认为最好的方法就是调用 FetchAttributesAsync。如果这导致 404,则该 blob 不存在。它只执行 1 个 HTTP 请求。

关于c# - 仅当 Blob 存在时才获取 Azure Blob 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54115575/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com