This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
A BlobServiceClient represents a Client to the Azure Storage Blob service allowing youto manipulate blob containers.
StorageClient
| Blob | Creates an instance of BlobServiceClient. |
| Blob | Creates an instance of BlobServiceClient. |
| account | |
| credential | Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the |
| url | Encoded URL string value. |
| create | Create a Blob container. Seehttps://learn.microsoft.com/rest/api/storageservices/create-container |
| delete | Deletes a Blob container. |
| find | Returns an async iterable iterator to find all blobs with specified tagunder the specified account. .byPage() returns an async iterable iterator to list the blobs in pages. Seehttps://learn.microsoft.com/rest/api/storageservices/get-blob-service-properties |
| from | Creates an instance of BlobServiceClient from connection string. |
| generate | Only available for BlobServiceClient constructed with a shared key credential. Generates a Blob account Shared Access Signature (SAS) URI based on the client propertiesand parameters passed in. The SAS is signed by the shared key credential of the client. Seehttps://learn.microsoft.com/rest/api/storageservices/create-account-sas |
| generate | Only available for BlobServiceClient constructed with a shared key credential. Generates string to sign for a Blob account Shared Access Signature (SAS) URI based onthe client properties and parameters passed in. The SAS is signed by the shared key credential of the client. Seehttps://learn.microsoft.com/rest/api/storageservices/create-account-sas |
| get | The Get Account Information operation returns the sku name and account kindfor the specified account.The Get Account Information operation is available on service versions beginningwith version 2018-03-28. Seehttps://learn.microsoft.com/rest/api/storageservices/get-account-information |
| get | Creates a BlobBatchClient object to conduct batch operations. Seehttps://learn.microsoft.com/rest/api/storageservices/blob-batch |
| get | Creates aContainerClient object |
| get | Gets the properties of a storage account’s Blob service, including propertiesfor Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. Seehttps://learn.microsoft.com/rest/api/storageservices/get-blob-service-properties |
| get | Retrieves statistics related to replication for the Blob service. It is onlyavailable on the secondary location endpoint when read-access geo-redundantreplication is enabled for the storage account. Seehttps://learn.microsoft.com/rest/api/storageservices/get-blob-service-stats |
| get | ONLY AVAILABLE WHEN USING BEARER TOKEN AUTHENTICATION (TokenCredential). Retrieves a user delegation key for the Blob service. This is only a valid operation when usingbearer token authentication. Seehttps://learn.microsoft.com/rest/api/storageservices/get-user-delegation-key |
| list | Returns an async iterable iterator to list all the containersunder the specified account. .byPage() returns an async iterable iterator to list the containers in pages. |
| set | Sets properties for a storage account’s Blob service endpoint, including propertiesfor Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings. Seehttps://learn.microsoft.com/rest/api/storageservices/set-blob-service-properties |
| undelete | 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. |
Creates an instance of BlobServiceClient.
new BlobServiceClient(url: string, pipeline: PipelineLike)string
A Client string pointing to Azure Storage blob service, such as"https://myaccount.blob.core.windows.net". You can append a SASif using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".
Call newPipeline() to create a defaultpipeline, or provide a customized pipeline.
Creates an instance of BlobServiceClient.
new BlobServiceClient(url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)string
A Client string pointing to Azure Storage blob service, such as"https://myaccount.blob.core.windows.net". You can append a SASif using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".
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.
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 nameconst 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 browsersconst sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);const blobServiceClient = new BlobServiceClient( `https://${account}.blob.core.windows.net`, sharedKeyCredential,);accountName: stringstring
Inherited From StorageClient.accountName
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.
credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredentialInherited From StorageClient.credential
Encoded URL string value.
url: stringstring
Inherited From StorageClient.url
Create a Blob container.
Seehttps://learn.microsoft.com/rest/api/storageservices/create-container
function createContainer(containerName: string, options?: ContainerCreateOptions): Promise<{ containerClient: ContainerClient, containerCreateResponse: ContainerCreateResponse }>string
Name of the container to create.
Options to configure Container Create operation.
Promise<{ containerClient: ContainerClient, containerCreateResponse: ContainerCreateResponse }>
Container creation response and the corresponding container client.
Deletes a Blob container.
function deleteContainer(containerName: string, options?: ContainerDeleteMethodOptions): Promise<ContainerDeleteResponse>string
Name of the container to delete.
Options to configure Container Delete operation.
Promise<ContainerDeleteResponse>
Container deletion response.
Returns an async iterable iterator to find all blobs with specified tagunder the specified account.
.byPage() returns an async iterable iterator to list the blobs in pages.
Seehttps://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 blobslet i = 1;for await (const blob of blobServiceClient.findBlobsByTags("tagkey='tagvalue'")) { console.log(`Blob ${i++}: ${blob.name}`);}// Use iter.next() to iterate the blobsi = 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 blobsi = 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 markeri = 1;let iterator = blobServiceClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 2 });let response = (await iterator.next()).value;// Prints 2 blob namesif (response.blobs) { for (const blob of response.blobs) { console.log(`Blob ${i++}: ${blob.name}`); }}// Gets next markerlet marker = response.continuationToken;// Passing next marker as continuationTokeniterator = blobServiceClient .findBlobsByTags("tagkey='tagvalue'") .byPage({ continuationToken: marker, maxPageSize: 10 });response = (await iterator.next()).value;// Prints blob namesif (response.blobs) { for (const blob of response.blobs) { console.log(`Blob ${i++}: ${blob.name}`); }}function findBlobsByTags(tagFilterSqlExpression: string, options?: ServiceFindBlobByTagsOptions): PagedAsyncIterableIterator<FilterBlobItem, ServiceFindBlobsByTagsSegmentResponse, PageSettings>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 to find blobs by tags.
Creates an instance of BlobServiceClient from connection string.
static function fromConnectionString(connectionString: string, options?: StoragePipelineOptions): BlobServiceClientstring
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.netSAS 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
Optional. Options to configure the HTTP pipeline.
Only available for BlobServiceClient constructed with a shared key credential.
Generates a Blob account Shared Access Signature (SAS) URI based on the client propertiesand parameters passed in. The SAS is signed by the shared key credential of the client.
Seehttps://learn.microsoft.com/rest/api/storageservices/create-account-sas
function generateAccountSasUrl(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): stringDate
Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not provided.
Specifies the list of permissions to be associated with the SAS.
string
Specifies the resource types associated with the shared access signature.
Optional parameters.
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 onthe client properties and parameters passed in. The SAS is signed by the shared key credential of the client.
Seehttps://learn.microsoft.com/rest/api/storageservices/create-account-sas
function generateSasStringToSign(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): stringDate
Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not provided.
Specifies the list of permissions to be associated with the SAS.
string
Specifies the resource types associated with the shared access signature.
Optional parameters.
string
An account SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
The Get Account Information operation returns the sku name and account kindfor the specified account.The Get Account Information operation is available on service versions beginningwith version 2018-03-28.
Seehttps://learn.microsoft.com/rest/api/storageservices/get-account-information
function getAccountInfo(options?: ServiceGetAccountInfoOptions): Promise<ServiceGetAccountInfoResponse>Options to the Service Get Account Info operation.
Promise<ServiceGetAccountInfoResponse>
Response data for the Service Get Account Info operation.
Creates a BlobBatchClient object to conduct batch operations.
Seehttps://learn.microsoft.com/rest/api/storageservices/blob-batch
function getBlobBatchClient(): BlobBatchClientA new BlobBatchClient object for this service.
Creates aContainerClient object
function getContainerClient(containerName: string): ContainerClientstring
A container name
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>");Gets the properties of a storage account’s Blob service, including propertiesfor Storage Analytics and CORS (Cross-Origin Resource Sharing) rules.
Seehttps://learn.microsoft.com/rest/api/storageservices/get-blob-service-properties
function getProperties(options?: ServiceGetPropertiesOptions): Promise<ServiceGetPropertiesResponse>Options to the Service Get Properties operation.
Promise<ServiceGetPropertiesResponse>
Response data for the Service Get Properties operation.
Retrieves statistics related to replication for the Blob service. It is onlyavailable on the secondary location endpoint when read-access geo-redundantreplication is enabled for the storage account.
Seehttps://learn.microsoft.com/rest/api/storageservices/get-blob-service-stats
function getStatistics(options?: ServiceGetStatisticsOptions): Promise<ServiceGetStatisticsResponse>Options to the Service Get Statistics operation.
Promise<ServiceGetStatisticsResponse>
Response data for the Service Get Statistics operation.
ONLY AVAILABLE WHEN USING BEARER TOKEN AUTHENTICATION (TokenCredential).
Retrieves a user delegation key for the Blob service. This is only a valid operation when usingbearer token authentication.
Seehttps://learn.microsoft.com/rest/api/storageservices/get-user-delegation-key
function getUserDelegationKey(startsOn: Date, expiresOn: Date, options?: ServiceGetUserDelegationKeyOptions): Promise<ServiceGetUserDelegationKeyResponse>Date
The start time for the user delegation SAS. Must be within 7 days of the current time
Date
The end time for the user delegation SAS. Must be within 7 days of the current time
Promise<ServiceGetUserDelegationKeyResponse>
Returns an async iterable iterator to list all the containersunder 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 containerslet i = 1;for await (const container of blobServiceClient.listContainers()) { console.log(`Container ${i++}: ${container.name}`);}// Use iter.next() to iterate the containersi = 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 containersi = 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 markeri = 1;let iterator = blobServiceClient.listContainers().byPage({ maxPageSize: 2 });let response = (await iterator.next()).value;// Prints 2 container namesif (response.containerItems) { for (const container of response.containerItems) { console.log(`Container ${i++}: ${container.name}`); }}// Gets next markerlet marker = response.continuationToken;// Passing next marker as continuationTokeniterator = blobServiceClient .listContainers() .byPage({ continuationToken: marker, maxPageSize: 10 });response = (await iterator.next()).value;// Prints 10 container namesif (response.containerItems) { for (const container of response.containerItems) { console.log(`Container ${i++}: ${container.name}`); }}function listContainers(options?: ServiceListContainersOptions): PagedAsyncIterableIterator<ContainerItem, ServiceListContainersSegmentResponse, PageSettings>Options to list containers.
An asyncIterableIterator that supports paging.
Sets properties for a storage account’s Blob service endpoint, including propertiesfor Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings.
Seehttps://learn.microsoft.com/rest/api/storageservices/set-blob-service-properties
function setProperties(properties: BlobServiceProperties, options?: ServiceSetPropertiesOptions): Promise<ServiceSetPropertiesResponse>Options to the Service Set Properties operation.
Promise<ServiceSetPropertiesResponse>
Response data for the Service Set Properties operation.
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.
function undeleteContainer(deletedContainerName: string, deletedContainerVersion: string, options?: ServiceUndeleteContainerOptions): Promise<{ containerClient: ContainerClient, containerUndeleteResponse: ContainerUndeleteResponse }>string
Name of the previously deleted container.
string
Version of the previously deleted container, used to uniquely identify the deleted container.
Options to configure Container Restore operation.
Promise<{ containerClient: ContainerClient, containerUndeleteResponse: ContainerUndeleteResponse }>
Container deletion response.