Package version:

A BlobServiceClient represents a Client to the Azure Storage Blob service allowing you to manipulate blob containers.

Hierarchy

  • StorageClient
    • BlobServiceClient

Constructors

  • Creates an instance of BlobServiceClient.

    Parameters

    • url: string

      A Client string pointing to Azure Storage blob service, such as "https://myaccount.blob.core.windows.net". You can append a SAS if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".

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

    • Optionaloptions: StoragePipelineOptions

      Optional. Options to configure the HTTP pipeline.

      Example using DefaultAzureCredential from @azure/identity:

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

      // Enter your storage account name
      const account = "<account>";
      const defaultAzureCredential = new DefaultAzureCredential();

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

      Example using an account name/key:

      import { StorageSharedKeyCredential, BlobServiceClient } from "@azure/storage-blob";

      const account = "<account>";
      const accountKey = "<accountkey>";

      // Use StorageSharedKeyCredential with storage account and account key
      // StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
      const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
      const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      sharedKeyCredential,
      );

    Returns BlobServiceClient

  • Creates an instance of BlobServiceClient.

    Parameters

    Returns BlobServiceClient

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.

Methods

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

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

    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: ServiceFindBlobByTagsOptions = {}

      Options to find blobs by tags.

    Returns PagedAsyncIterableIterator<FilterBlobItem, ServiceFindBlobsByTagsSegmentResponse>

    https://learn.microsoft.com/rest/api/storageservices/get-blob-service-properties

    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(),
    );

    // Use for await to iterate the blobs
    let i = 1;
    for await (const blob of blobServiceClient.findBlobsByTags("tagkey='tagvalue'")) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }

    // Use iter.next() to iterate the blobs
    i = 1;
    const iter = blobServiceClient.findBlobsByTags("tagkey='tagvalue'");
    let { value, done } = await iter.next();
    while (!done) {
    console.log(`Blob ${i++}: ${value.name}`);
    ({ value, done } = await iter.next());
    }

    // Use byPage() to iterate the blobs
    i = 1;
    for await (const page of blobServiceClient
    .findBlobsByTags("tagkey='tagvalue'")
    .byPage({ maxPageSize: 20 })) {
    for (const blob of page.blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }

    // Use paging with a marker
    i = 1;
    let iterator = blobServiceClient.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 = blobServiceClient
    .findBlobsByTags("tagkey='tagvalue'")
    .byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;

    // Prints blob names
    if (response.blobs) {
    for (const blob of response.blobs) {
    console.log(`Blob ${i++}: ${blob.name}`);
    }
    }
  • Only available for BlobServiceClient constructed with a shared key credential.

    Generates a Blob account Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

    Parameters

    • OptionalexpiresOn: any

      Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not provided.

    • permissions: AccountSASPermissions = ...

      Specifies the list of permissions to be associated with the SAS.

    • resourceTypes: string = "sco"

      Specifies the resource types associated with the shared access signature.

    • options: ServiceGenerateAccountSasUrlOptions = {}

      Optional parameters.

    Returns string

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

  • Only available for BlobServiceClient constructed with a shared key credential.

    Generates string to sign for a Blob account Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

    Parameters

    • OptionalexpiresOn: any

      Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not provided.

    • permissions: AccountSASPermissions = ...

      Specifies the list of permissions to be associated with the SAS.

    • resourceTypes: string = "sco"

      Specifies the resource types associated with the shared access signature.

    • options: ServiceGenerateAccountSasUrlOptions = {}

      Optional parameters.

    Returns string

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

  • Creates a ContainerClient object

    Parameters

    • containerName: string

      A container name

    Returns ContainerClient

    A new ContainerClient object for the given container 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 containerClient = blobServiceClient.getContainerClient("<container name>");
  • Returns an async iterable iterator to list all the containers under the specified account.

    .byPage() returns an async iterable iterator to list the containers 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(),
    );

    // Use for await to iterate the containers
    let i = 1;
    for await (const container of blobServiceClient.listContainers()) {
    console.log(`Container ${i++}: ${container.name}`);
    }

    // Use iter.next() to iterate the containers
    i = 1;
    const iter = blobServiceClient.listContainers();
    let { value, done } = await iter.next();
    while (!done) {
    console.log(`Container ${i++}: ${value.name}`);
    ({ value, done } = await iter.next());
    }

    // Use byPage() to iterate the containers
    i = 1;
    for await (const page of blobServiceClient.listContainers().byPage({ maxPageSize: 20 })) {
    for (const container of page.containerItems) {
    console.log(`Container ${i++}: ${container.name}`);
    }
    }

    // Use paging with a marker
    i = 1;
    let iterator = blobServiceClient.listContainers().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;

    // Prints 2 container names
    if (response.containerItems) {
    for (const container of response.containerItems) {
    console.log(`Container ${i++}: ${container.name}`);
    }
    }

    // Gets next marker
    let marker = response.continuationToken;
    // Passing next marker as continuationToken
    iterator = blobServiceClient
    .listContainers()
    .byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;

    // Prints 10 container names
    if (response.containerItems) {
    for (const container of response.containerItems) {
    console.log(`Container ${i++}: ${container.name}`);
    }
    }

    Parameters

    Returns PagedAsyncIterableIterator<ContainerItem, ServiceListContainersSegmentResponse>

    An asyncIterableIterator that supports paging.

  • Restore a previously deleted Blob container. This API is only functional if Container Soft Delete is enabled for the storage account associated with the container.

    Parameters

    • deletedContainerName: string

      Name of the previously deleted container.

    • deletedContainerVersion: string

      Version of the previously deleted container, used to uniquely identify the deleted container.

    • options: ServiceUndeleteContainerOptions = {}

      Options to configure Container Restore operation.

    Returns Promise<{
        containerClient: ContainerClient;
        containerUndeleteResponse: ContainerUndeleteResponse;
    }>

    Container deletion response.

  • Creates an instance of BlobServiceClient from connection string.

    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

    • Optionaloptions: StoragePipelineOptions

      Optional. Options to configure the HTTP pipeline.

    Returns BlobServiceClient