Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ContainerClient

Package version

A ContainerClient represents a URL to the Azure Storage container allowing you to manipulate its blobs.

export

Hierarchy

Index

Constructors

constructor

Properties

accountName

accountName: string

credential

credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential

Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.

memberof

StorageClient

Protected isHttps

isHttps: boolean
memberof

StorageClient

Protected storageClientContext

storageClientContext: StorageClientContext

StorageClient is a reference to protocol layer operations entry, which is generated by AutoRest generator.

memberof

StorageClient

url

url: string

Encoded URL string value.

memberof

StorageClient

Accessors

containerName

  • get containerName(): string

Methods

create

createIfNotExists

delete

deleteBlob

deleteIfExists

exists

  • Returns true if the Azure container resource represented by this client exists; false otherwise.

    NOTE: use this function with care since an existing container might be deleted by other clients or applications. Vice versa new containers with the same name might be added by other clients or applications after this function completes.

    memberof

    ContainerClient

    Parameters

    Returns Promise<boolean>

generateSasUrl

getAccessPolicy

getAppendBlobClient

getBlobBatchClient

getBlobClient

getBlobLeaseClient

getBlockBlobClient

  • Creates a BlockBlobClient

    memberof

    ContainerClient

    Example usage:

    const content = "Hello world!";
    
    const blockBlobClient = containerClient.getBlockBlobClient("<blob name>");
    const uploadBlobResponse = await blockBlobClient.upload(content, content.length);

    Parameters

    • blobName: string

      A block blob name

    Returns BlockBlobClient

getPageBlobClient

getProperties

listBlobsByHierarchy

  • Returns an async iterable iterator to list all the blobs by hierarchy. under the specified account.

    .byPage() returns an async iterable iterator to list the blobs by hierarchy in pages.

    Example using for await syntax:

    for await (const item of containerClient.listBlobsByHierarchy("/")) {
      if (item.kind === "prefix") {
        console.log(`\tBlobPrefix: ${item.name}`);
      } else {
        console.log(`\tBlobItem: name - ${item.name}, last modified - ${item.properties.lastModified}`);
      }
    }

    Example using iter.next():

    let iter = containerClient.listBlobsByHierarchy("/", { prefix: "prefix1/" });
    let entity = await iter.next();
    while (!entity.done) {
      let item = entity.value;
      if (item.kind === "prefix") {
        console.log(`\tBlobPrefix: ${item.name}`);
      } else {
        console.log(`\tBlobItem: name - ${item.name}, last modified - ${item.properties.lastModified}`);
      }
      entity = await iter.next();
    }

    Example using byPage():

    console.log("Listing blobs by hierarchy by page");
    for await (const response of containerClient.listBlobsByHierarchy("/").byPage()) {
      const segment = response.segment;
      if (segment.blobPrefixes) {
        for (const prefix of segment.blobPrefixes) {
          console.log(`\tBlobPrefix: ${prefix.name}`);
        }
      }
      for (const blob of response.segment.blobItems) {
        console.log(`\tBlobItem: name - ${blob.name}, last modified - ${blob.properties.lastModified}`);
      }
    }

    Example using paging with a max page size:

    console.log("Listing blobs by hierarchy by page, specifying a prefix and a max page size");
    
    let i = 1;
    for await (const response of containerClient.listBlobsByHierarchy("/", { prefix: "prefix2/sub1/"}).byPage({ maxPageSize: 2 })) {
      console.log(`Page ${i++}`);
      const segment = response.segment;
    
      if (segment.blobPrefixes) {
        for (const prefix of segment.blobPrefixes) {
          console.log(`\tBlobPrefix: ${prefix.name}`);
        }
      }
    
      for (const blob of response.segment.blobItems) {
        console.log(`\tBlobItem: name - ${blob.name}, last modified - ${blob.properties.lastModified}`);
      }
    }
    memberof

    ContainerClient

    Parameters

    • delimiter: string

      The character or string used to define the virtual hierarchy

    • Default value options: ContainerListBlobsOptions = {}

    Returns PagedAsyncIterableIterator<({ kind: "prefix" } & BlobPrefix) | ({ kind: "blob" } & BlobItem), ContainerListBlobHierarchySegmentResponse>

    {(PagedAsyncIterableIterator< { kind: "prefix" } & BlobPrefix | { kind: "blob" } & BlobItem, ContainerListBlobHierarchySegmentResponse>)}

listBlobsFlat

  • Returns an async iterable iterator to list all the blobs under the specified account.

    .byPage() returns an async iterable iterator to list the blobs in pages.

    Example using for await syntax:

    // Get the containerClient before you run these snippets,
    // Can be obtained from `blobServiceClient.getContainerClient("<your-container-name>");`
    let i = 1;
    for await (const blob of containerClient.listBlobsFlat()) {
      console.log(`Blob ${i++}: ${blob.name}`);
    }

    Example using iter.next():

    let i = 1;
    let iter = containerClient.listBlobsFlat();
    let blobItem = await iter.next();
    while (!blobItem.done) {
      console.log(`Blob ${i++}: ${blobItem.value.name}`);
      blobItem = await iter.next();
    }

    Example using byPage():

    // passing optional maxPageSize in the page settings
    let i = 1;
    for await (const response of containerClient.listBlobsFlat().byPage({ maxPageSize: 20 })) {
      for (const blob of response.segment.blobItems) {
        console.log(`Blob ${i++}: ${blob.name}`);
      }
    }

    Example using paging with a marker:

    let i = 1;
    let iterator = containerClient.listBlobsFlat().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    
    // Prints 2 blob names
    for (const blob of response.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
    }
    
    // Gets next marker
    let marker = response.continuationToken;
    
    // Passing next marker as continuationToken
    
    iterator = containerClient.listBlobsFlat().byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    
    // Prints 10 blob names
    for (const blob of response.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
    }
    memberof

    ContainerClient

    Parameters

    Returns PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse>

    An asyncIterableIterator that supports paging.

setAccessPolicy

setMetadata

uploadBlockBlob

Generated using TypeDoc