Azure Rest Api 列表容器:参数标记

Azure Rest Api List container : Parameter Marker

大家好,我正在构建一个与 Azure Storage Rest 交互的客户端 API。

我正在查看文档 https://docs.microsoft.com/ru-ru/rest/api/storageservices/fileservices/list-containers2:

并且不理解可以与 Azure 请求一起发送的参数前缀和标记的使用。

它说:

前缀

Optional. Filters the results to return only containers whose name begins with the specified prefix.

标记

Optional. A string value that identifies the portion of the list of containers to be returned with the next listing operation. The operation returns the NextMarker value within the response body if the listing operation did not return all containers remaining to be listed with the current page. The NextMarker value can be used as the value for the marker parameter in a subsequent call to request the next page of list items.

The marker value is opaque to the client.

有了前缀,我认为:

如果我有目录结构:

file01.txt
images/image01.jpg
images/folder/image001.jpg
fightVideo/subFolder/current/video001.mpg
fightVideo/subFolder/current/video002.mpg

If I give prefix container name as "fight". It should return fightVideo.

但我不确定。

对于 Marker,我不明白它有什么用?

Please can someone explain the use of Prefix and Marker with examples?

如果要列出的 blob 太多,则响应包含 NextMarker 元素。

<?xml version="1.0" encoding="utf-8"?>  
<EnumerationResults ServiceEndpoint="https://myaccount.blob.core.windows.net">  
  <Prefix>string-value</Prefix>  
  <Marker>string-value</Marker>  
  <MaxResults>int-value</MaxResults>  
  <Containers>  
    <Container>  
      <Name>container-name</Name>  
      <Properties>  
        <Last-Modified>date/time-value</Last-Modified>  
        <Etag>etag</Etag>  
        <LeaseStatus>locked | unlocked</LeaseStatus>  
        <LeaseState>available | leased | expired | breaking | broken</LeaseState>  
        <LeaseDuration>infinite | fixed</LeaseDuration> 
        <PublicAccess>container | blob</PublicAccess>       
      </Properties>  
      <Metadata>  
        <metadata-name>value</metadata-name>  
      </Metadata>  
    </Container>  
  </Containers>  
  <NextMarker>marker-value</NextMarker>  
</EnumerationResults>

REST API 文档提到标记值可用于后续调用以请求下一组列表项。

您可以将标记想象成分页器索引。

在列出容器的上下文中,如果您指定 prefix 参数,它将列出名称以该前缀值开头的容器。它与列出 blob 无关。

List blobs 操作也支持此 prefix 参数,当您指定此参数时,它将列出以该前缀值开头的 blob 名称。

所以您给出的示例是用于列出 blob,当您在那里指定 flight 作为前缀时,您将返回 fightVideo/subFolder/current/video001.mpgfightVideo/subFolder/current/video002.mpg 作为响应,但不会在您调用时返回列出具有此前缀的容器。

关于marker,Kalyan 的解释是正确的,但让我再补充一点。

本质上,Azure 存储服务是一项共享服务,您根本无法要求它一次性 return 所有结果(如果我们从 SQL 世界进行类比,您根本做不到 SELECT * FROM TABLE 之类的事情)。对服务的每个请求都分配了一个预定义的超时,并且响应将包括在该时间内获取的项目 + 如果服务认为有更多可用数据,则可以选择一个令牌。此令牌称为 continuation token。为了获得下一组项目,您需要在下一个请求的标记参数中传递此延续令牌。

每次调用存储服务都会尝试 return 预定义的最大项目数。对于列表 blob containers/blobs,此限制为 5000 个项目。对于列表 tables/entities,此限制为 1000 件。如果您的帐户中有更多项目,那么除了此数据存储服务 return 之外,您还会收到一个延续令牌,告诉您有更多可用数据。

请注意,尽管存在限制,但您不能总是假设您会获得这些记录数。根据多种情况,您很可能不会取回任何数据,但仍会收到延续令牌。所以你的代码也需要处理这种情况。