Package version:

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

Hierarchy

  • StorageClient
    • ContainerClient

Constructors

  • Creates an instance of ContainerClient.

    Parameters

    • connectionString: string

      Account connection string or a SAS connection string of an Azure storage account. [ Note - Account connection string can only be used in NODE.JS runtime. ] Account connection string example - DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS connection string example - BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString

    • containerName: string

      Container name.

    • Optionaloptions: StoragePipelineOptions

      Optional. Options to configure the HTTP pipeline.

    Returns ContainerClient

  • Creates an instance of ContainerClient. This method accepts an URL pointing to a container. Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped. If a blob name includes ? or %, blob name must be encoded in the URL.

    Parameters

    Returns ContainerClient

  • Creates an instance of ContainerClient. This method accepts an URL pointing to a container. Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped. If a blob name includes ? or %, blob name must be encoded in the URL.

    Parameters

    Returns ContainerClient

Properties

accountName: string
credential: any

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.

isHttps: boolean
storageClientContext: StorageClient

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

url: string

Encoded URL string value.

Accessors

Methods

  • 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.

    Parameters

    Returns Promise<boolean>

  • Returns an async iterable iterator to find all blobs with specified tag under the specified container.

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

    Example using for await syntax:

    import { BlobServiceClient } from "@azure/storage-blob";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    new DefaultAzureCredential(),
    );

    const containerName = "<container name>";
    const containerClient = blobServiceClient.getContainerClient(containerName);

    // Example using `for await` syntax
    let i = 1;
    for await (const blob of containerClient.findBlobsByTags("tagkey='tagvalue'")) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }

    // Example using `iter.next()` syntax
    i = 1;
    const iter = containerClient.findBlobsByTags("tagkey='tagvalue'");
    let { value, done } = await iter.next();
    while (!done) {
    console.log(`Blob ${i++}: ${value.name}`);
    ({ value, done } = await iter.next());
    }

    // Example using `byPage()` syntax
    i = 1;
    for await (const page of containerClient
    .findBlobsByTags("tagkey='tagvalue'")
    .byPage({ maxPageSize: 20 })) {
    for (const blob of page.blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    // Example using paging with a marker
    i = 1;
    let iterator = containerClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    // Prints 2 blob names
    if (response.blobs) {
    for (const blob of response.blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }
    // Gets next marker
    let marker = response.continuationToken;
    // Passing next marker as continuationToken
    iterator = containerClient
    .findBlobsByTags("tagkey='tagvalue'")
    .byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    // Prints 10 blob names
    if (response.blobs) {
    for (const blob of response.blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    Parameters

    • tagFilterSqlExpression: string

      The where parameter enables the caller to query blobs whose tags match a given expression. The given expression must evaluate to true for a blob to be returned in the results. The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter; however, only a subset of the OData filter syntax is supported in the Blob service.

    • options: ContainerFindBlobByTagsOptions = {}

      Options to find blobs by tags.

    Returns PagedAsyncIterableIterator<FilterBlobItem, ContainerFindBlobsByTagsSegmentResponse>

  • Generates string to sign for a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.

    Parameters

    • options: ContainerGenerateSasUrlOptions

      Optional parameters.

    • userDelegationKey: UserDelegationKey

      Return value of blobServiceClient.getUserDelegationKey()

    Returns string

    The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

  • Generates a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.

    Parameters

    • options: ContainerGenerateSasUrlOptions

      Optional parameters.

    • userDelegationKey: UserDelegationKey

      Return value of blobServiceClient.getUserDelegationKey()

    Returns Promise<string>

    The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

  • Creates a BlockBlobClient

    Parameters

    • blobName: string

      A block blob name

      Example usage:

      import { BlobServiceClient } from "@azure/storage-blob";
      import { DefaultAzureCredential } from "@azure/identity";

      const account = "<account>";
      const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      new DefaultAzureCredential(),
      );

      const containerName = "<container name>";
      const blobName = "<blob name>";
      const containerClient = blobServiceClient.getContainerClient(containerName);
      const blockBlobClient = containerClient.getBlockBlobClient(blobName);

      const content = "Hello world!";
      const uploadBlobResponse = await blockBlobClient.upload(content, content.length);

    Returns BlockBlobClient

  • 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.

    import { BlobServiceClient } from "@azure/storage-blob";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    new DefaultAzureCredential(),
    );

    const containerName = "<container name>";
    const containerClient = blobServiceClient.getContainerClient(containerName);

    // Example using `for await` syntax
    let i = 1;
    const blobs = containerClient.listBlobsByHierarchy("/");
    for await (const blob of blobs) {
    if (blob.kind === "prefix") {
    console.log(`\tBlobPrefix: ${blob.name}`);
    } else {
    console.log(`\tBlobItem: name - ${blob.name}`);
    }
    }

    // Example using `iter.next()` syntax
    i = 1;
    const iter = containerClient.listBlobsByHierarchy("/");
    let { value, done } = await iter.next();
    while (!done) {
    if (value.kind === "prefix") {
    console.log(`\tBlobPrefix: ${value.name}`);
    } else {
    console.log(`\tBlobItem: name - ${value.name}`);
    }
    ({ value, done } = await iter.next());
    }

    // Example using `byPage()` syntax
    i = 1;
    for await (const page of containerClient.listBlobsByHierarchy("/").byPage({ maxPageSize: 20 })) {
    const segment = page.segment;
    if (segment.blobPrefixes) {
    for (const prefix of segment.blobPrefixes) {
    console.log(`\tBlobPrefix: ${prefix.name}`);
    }
    }
    for (const blob of page.segment.blobItems) {
    console.log(`\tBlobItem: name - ${blob.name}`);
    }
    }

    // Example using paging with a marker
    i = 1;
    let iterator = containerClient.listBlobsByHierarchy("/").byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    // Prints 2 blob names
    if (response.blobPrefixes) {
    for (const prefix of response.blobPrefixes) {
    console.log(`\tBlobPrefix: ${prefix.name}`);
    }
    }
    if (response.segment.blobItems) {
    for (const blob of response.segment.blobItems) {
    console.log(`\tBlobItem: name - ${blob.name}`);
    }
    }
    // Gets next marker
    let marker = response.continuationToken;
    // Passing next marker as continuationToken
    iterator = containerClient
    .listBlobsByHierarchy("/")
    .byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    // Prints 10 blob names
    if (response.blobPrefixes) {
    for (const prefix of response.blobPrefixes) {
    console.log(`\tBlobPrefix: ${prefix.name}`);
    }
    }
    if (response.segment.blobItems) {
    for (const blob of response.segment.blobItems) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    Parameters

    • delimiter: string

      The character or string used to define the virtual hierarchy

    • options: ContainerListBlobsOptions = {}

      Options to list blobs operation.

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

  • 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.

    import { BlobServiceClient } from "@azure/storage-blob";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    new DefaultAzureCredential(),
    );

    const containerName = "<container name>";
    const containerClient = blobServiceClient.getContainerClient(containerName);

    // Example using `for await` syntax
    let i = 1;
    const blobs = containerClient.listBlobsFlat();
    for await (const blob of blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }

    // Example using `iter.next()` syntax
    i = 1;
    const iter = containerClient.listBlobsFlat();
    let { value, done } = await iter.next();
    while (!done) {
    console.log(`Blob ${i++}: ${value.name}`);
    ({ value, done } = await iter.next());
    }

    // Example using `byPage()` syntax
    i = 1;
    for await (const page of containerClient.listBlobsFlat().byPage({ maxPageSize: 20 })) {
    for (const blob of page.segment.blobItems) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    // Example using paging with a marker
    i = 1;
    let iterator = containerClient.listBlobsFlat().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    // Prints 2 blob names
    if (response.segment.blobItems) {
    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
    if (response.segment.blobItems) {
    for (const blob of response.segment.blobItems) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    Parameters

    Returns PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse>

    An asyncIterableIterator that supports paging.

  • Sets the permissions for the specified container. The permissions indicate whether blobs in a container may be accessed publicly.

    When you set permissions for a container, the existing permissions are replaced. If no access or containerAcl provided, the existing container ACL will be removed.

    When you establish a stored access policy on a container, it may take up to 30 seconds to take effect. During this interval, a shared access signature that is associated with the stored access policy will fail with status code 403 (Forbidden), until the access policy becomes active.

    Parameters

    • Optionalaccess: PublicAccessType

      The level of public access to data in the container.

    • OptionalcontainerAcl: {}

      Array of elements each having a unique Id and details of the access policy.

      • options: ContainerSetAccessPolicyOptions = {}

        Options to Container Set Access Policy operation.

      Returns Promise<ContainerSetAccessPolicyResponse>