skip to Main Content

I am trying to get list of version ids for a blob using node.js.

    async function getBlobNameAndVersions() {
    
      for await (const blob of containerClient.listBlobsFlat(includeVersions?: true)) {
     
        const tempBlockBlobClient = containerClient.getBlockBlobClient(blob.name);
   
        console.log(`ntname: ${blob.versionId}ntURL: ${tempBlockBlobClient.name}n`);
    
      }
    
    }

getBlobNameAndVersions()

Received error saying "ReferenceError: inlcudeVersions is not defined"

When looked at the reference listBlobsFlat, below were options to include versions.

listBlobsFlat(options?: ContainerListBlobsOptions): PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse>;
/**
 * Returns an AsyncIterableIterator for ContainerListBlobHierarchySegmentResponse
 *
 * @param delimiter - The character or string used to define the virtual hierarchy
 * @param marker - A string value that identifies the portion of
 *                          the list of blobs to be returned with the next listing operation. The
 *                          operation returns the ContinuationToken value within the response body if the
 *                          listing operation did not return all blobs remaining to be listed
 *                          with the current page. The ContinuationToken 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.
 * @param options - Options to list blobs operation. 

Tried using options as below.

export declare interface ContainerListBlobsOptions extends CommonOptions {
     * Specifies whether versions should be included in the enumeration. Versions are listed from oldest to newest in the response.
     */
    includeVersions?: boolean;
}

2

Answers


  1. Chosen as BEST ANSWER

    Updated Code is working to get version ids of blobs and its URL's

    async function getBlobNameAndVersions() {
          for await (const blob of containerClient.listBlobsFlat({includeVersions: true})){
    
            const tempBlockBlobClient = containerClient.getBlockBlobClient(blob.name);
        
            console.log(`ntversion: ${blob.versionId}ntURL: ${tempBlockBlobClient.url}n`);
          }
    }
    

  2. You would need to pass the options as an object i.e. instead of passing includeVersions?: true, you would need to use {includeVersions: true}.

    So your code would be something like:

    async function getBlobNameAndVersions() {
    
      for await (const blob of containerClient.listBlobsFlat({includeVersions: true})) {
      
        const tempBlockBlobClient = containerClient.getBlockBlobClient(blob.name);
    
        console.log(`ntname: ${blob.name}ntURL: ${tempBlockBlobClient.url}n`);
    
      }
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search