Arjun Chaudhary
Arjun Chaudhary

Reputation: 2453

Azure Rest Api List container : Parameter Marker

Hi Guys I am building a Client which Interact with Azure Storage Rest API.

I was going through documentation https://learn.microsoft.com/ru-ru/rest/api/storageservices/fileservices/list-containers2:

And didn't understood the use of parameter prefix and marker which can be send along with Azure request.

It says:

prefix

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

marker

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.

With Prefix, I think:

If i have dir structure:

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.

But I am not sure.

And for Marker I don't understand whats its use?

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

Upvotes: 1

Views: 1258

Answers (2)

Gaurav Mantri
Gaurav Mantri

Reputation: 136186

In context of listing containers, if you specify prefix parameter it will list the containers names of which start with that prefix value. It has nothing to do with listing blobs.

List blobs operation also supports this prefix parameter and when you specify this parameter, it will list the blobs names of which start with that prefix value.

So the example you have given is for listing blobs and when you specify flight as prefix there, you will get back fightVideo/subFolder/current/video001.mpg and fightVideo/subFolder/current/video002.mpg in response but not when you call list containers with this prefix.

Regarding marker, Kalyan's explanation is correct but let me add a little bit more to that.

Essentially Azure Storage Service is a shared service and you simply can't ask it to return all the results in one go (if we were to take an analogy from SQL world, you simply can't do SELECT * FROM TABLE kind of thing). Each request to the service is assigned a predefined timeout and the response would include the items fetched in that time + optionally a token if the service thinks that there's more data available. This token is called continuation token. In order to get the next set of items, you would need to pass this continuation token in the marker parameter in your next request.

Each call to storage service will try to return a predefined maximum number of items. For listing blob containers/blobs, this limit is 5000 items. For listing tables/entities, this limit is 1000 items. If there are more items in your account, then apart from this data storage service returns you a continuation token which tells you that there's more data available.

Please note that even though the limit is there but you can't always assume that you will get these number of records. Based on a number of conditions, it is quite possible that you don't get back any data but still receive a continuation token. So your code need to handle this condition as well.

Upvotes: 3

Kalyan
Kalyan

Reputation: 1200

If there are too many blobs to be listed, then the response contains the NextMarker element.

<?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>

The REST API documentation mentions that the marker value can be used in a subsequent call to request the next set of list items.

You can imagine marker as a paginatator index.

Upvotes: 1

Related Questions