A ContainerClient represents a URL to the Azure Storage container allowing you to manipulate its blobs.
Inherited Properties accountName credentialSuch 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.
Encoded URL string value.
Methods create(ContainerCreateOptions)Creates a new container under the specified account. If the container with the same name already exists, the operation fails.
See https://learn.microsoft.com/rest/api/storageservices/create-container Naming rules: See https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata
createIfNotExists(ContainerCreateOptions)Creates a new container under the specified account. If the container with the same name already exists, it is not changed.
See https://learn.microsoft.com/rest/api/storageservices/create-container Naming rules: See https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata
delete(ContainerDeleteMethodOptions)Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.
See https://learn.microsoft.com/rest/api/storageservices/delete-container
deleteBlob(string, ContainerDeleteBlobOptions)Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the Delete Blob operation.
See https://learn.microsoft.com/rest/api/storageservices/delete-blob
deleteIfExists(ContainerDeleteMethodOptions)Marks the specified container for deletion if it exists. The container and any blobs contained within it are later deleted during garbage collection.
See https://learn.microsoft.com/rest/api/storageservices/delete-container
exists(ContainerExistsOptions)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.
findBlobsByTags(string, ContainerFindBlobByTagsOptions)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}`);
}
}
generateSasStringToSign(ContainerGenerateSasUrlOptions)
Only available for ContainerClient constructed with a shared key credential.
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 shared key credential of the client.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
generateSasUrl(ContainerGenerateSasUrlOptions)Only available for ContainerClient constructed with a shared key credential.
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 shared key credential of the client.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
generateUserDelegationSasStringToSign(ContainerGenerateSasUrlOptions, UserDelegationKey)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.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
generateUserDelegationSasUrl(ContainerGenerateSasUrlOptions, UserDelegationKey)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.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
getAccessPolicy(ContainerGetAccessPolicyOptions)Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.
WARNING: JavaScript Date will potentially lose precision when parsing startsOn and expiresOn strings. For example, new Date("2018-12-31T03:44:23.8827891Z").toISOString() will get "2018-12-31T03:44:23.882Z".
See https://learn.microsoft.com/rest/api/storageservices/get-container-acl
getAccountInfo(ContainerGetAccountInfoOptions)The Get Account Information operation returns the sku name and account kind for the specified account. The Get Account Information operation is available on service versions beginning with version 2018-03-28.
See https://learn.microsoft.com/rest/api/storageservices/get-account-information
getAppendBlobClient(string)Creates an AppendBlobClient
getBlobBatchClient()Creates a BlobBatchClient object to conduct batch operations.
See https://learn.microsoft.com/rest/api/storageservices/blob-batch
getBlobClient(string)Creates a BlobClient
getBlobLeaseClient(string)Get a BlobLeaseClient that manages leases on the container.
getBlockBlobClient(string)Creates a BlockBlobClient
getPageBlobClient(string)Creates a PageBlobClient
getProperties(ContainerGetPropertiesOptions)Returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs.
See https://learn.microsoft.com/rest/api/storageservices/get-container-properties
WARNING: The metadata
object returned in the response will have its keys in lowercase, even if they originally contained uppercase characters. This differs from the metadata keys returned by the listContainers
method of BlobServiceClient using the includeMetadata
option, which will retain their original casing.
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}`);
}
}
listBlobsFlat(ContainerListBlobsOptions)
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}`);
}
}
setAccessPolicy(PublicAccessType, SignedIdentifier[], ContainerSetAccessPolicyOptions)
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.
See https://learn.microsoft.com/rest/api/storageservices/set-container-acl
setMetadata(Metadata, ContainerSetMetadataOptions)Sets one or more user-defined name-value pairs for the specified container.
If no option provided, or no metadata defined in the parameter, the container metadata will be removed.
See https://learn.microsoft.com/rest/api/storageservices/set-container-metadata
uploadBlockBlob(string, RequestBodyType, number, BlockBlobUploadOptions)Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use stageBlock and commitBlockList.
This is a non-parallel uploading method, please use uploadFile, uploadStream or uploadBrowserData for better performance with concurrency uploading.
See https://learn.microsoft.com/rest/api/storageservices/put-blob
Constructor Details ContainerClient(string, PipelineLike)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.
new ContainerClient(url: string, pipeline: PipelineLike)
Parameters
string
A URL string pointing to Azure Storage container, such as "https://myaccount.blob.core.windows.net/mycontainer". You can append a SAS if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net/mycontainer?sasString".
Call newPipeline() to create a default pipeline, or provide a customized pipeline.
ContainerClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)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.
new ContainerClient(url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)
Parameters
string
A URL string pointing to Azure Storage container, such as "https://myaccount.blob.core.windows.net/mycontainer". You can append a SAS if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net/mycontainer?sasString".
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.
Creates an instance of ContainerClient.
new ContainerClient(connectionString: string, containerName: string, options?: StoragePipelineOptions)
Parameters
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
string
Container name.
Property Details containerNameThe name of the container.
string containerName
Property Value
string
Inherited Property Details accountNameaccountName: string
Property Value
string
Inherited From StorageClient.accountName
credentialSuch 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 | TokenCredential
Property Value
StorageSharedKeyCredential | AnonymousCredential | TokenCredential
Inherited From StorageClient.credential
urlEncoded URL string value.
url: string
Property Value
string
Inherited From StorageClient.url
Method Details create(ContainerCreateOptions) createIfNotExists(ContainerCreateOptions) delete(ContainerDeleteMethodOptions) deleteBlob(string, ContainerDeleteBlobOptions)Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the Delete Blob operation.
See https://learn.microsoft.com/rest/api/storageservices/delete-blob
function deleteBlob(blobName: string, options?: ContainerDeleteBlobOptions): Promise<BlobDeleteResponse>
Parameters Returns
Promise<BlobDeleteResponse>
Block blob deletion response data.
deleteIfExists(ContainerDeleteMethodOptions) exists(ContainerExistsOptions)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.
function exists(options?: ContainerExistsOptions): Promise<boolean>
Parameters Returns
Promise<boolean>
findBlobsByTags(string, ContainerFindBlobByTagsOptions)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}`);
}
}
function findBlobsByTags(tagFilterSqlExpression: string, options?: ContainerFindBlobByTagsOptions): PagedAsyncIterableIterator<FilterBlobItem, ContainerFindBlobsByTagsSegmentResponse, PageSettings>
Parameters
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.
ReturnsPagedAsyncIterableIterator<FilterBlobItem, ContainerFindBlobsByTagsSegmentResponse, PageSettings>
generateSasStringToSign(ContainerGenerateSasUrlOptions)Only available for ContainerClient constructed with a shared key credential.
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 shared key credential of the client.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
function generateSasStringToSign(options: ContainerGenerateSasUrlOptions): string
Parameters Returns
string
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
generateSasUrl(ContainerGenerateSasUrlOptions)Only available for ContainerClient constructed with a shared key credential.
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 shared key credential of the client.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
function generateSasUrl(options: ContainerGenerateSasUrlOptions): Promise<string>
Parameters Returns
Promise<string>
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
generateUserDelegationSasStringToSign(ContainerGenerateSasUrlOptions, UserDelegationKey)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.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
function generateUserDelegationSasStringToSign(options: ContainerGenerateSasUrlOptions, userDelegationKey: UserDelegationKey): string
Parameters
Return value of blobServiceClient.getUserDelegationKey()
string
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
generateUserDelegationSasUrl(ContainerGenerateSasUrlOptions, UserDelegationKey)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.
See https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
function generateUserDelegationSasUrl(options: ContainerGenerateSasUrlOptions, userDelegationKey: UserDelegationKey): Promise<string>
Parameters
Return value of blobServiceClient.getUserDelegationKey()
Promise<string>
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
getAccessPolicy(ContainerGetAccessPolicyOptions)Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.
WARNING: JavaScript Date will potentially lose precision when parsing startsOn and expiresOn strings. For example, new Date("2018-12-31T03:44:23.8827891Z").toISOString() will get "2018-12-31T03:44:23.882Z".
See https://learn.microsoft.com/rest/api/storageservices/get-container-acl
function getAccessPolicy(options?: ContainerGetAccessPolicyOptions): Promise<ContainerGetAccessPolicyResponse>
Parameters Returns
Promise<ContainerGetAccessPolicyResponse>
getAccountInfo(ContainerGetAccountInfoOptions) getAppendBlobClient(string)Creates an AppendBlobClient
function getAppendBlobClient(blobName: string): AppendBlobClient
Parameters
string
An append blob name
Returns getBlobClient(string)Creates a BlobClient
function getBlobClient(blobName: string): BlobClient
Parameters
string
A blob name
ReturnsA new BlobClient object for the given blob name.
getBlobLeaseClient(string)Get a BlobLeaseClient that manages leases on the container.
function getBlobLeaseClient(proposeLeaseId?: string): BlobLeaseClient
Parameters
string
Initial proposed lease Id.
ReturnsA new BlobLeaseClient object for managing leases on the container.
getBlockBlobClient(string)Creates a BlockBlobClient
function getBlockBlobClient(blobName: string): BlockBlobClient
Parameters
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 getPageBlobClient(string)
Creates a PageBlobClient
function getPageBlobClient(blobName: string): PageBlobClient
Parameters
string
A page blob name
Returns getProperties(ContainerGetPropertiesOptions)Returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs.
See https://learn.microsoft.com/rest/api/storageservices/get-container-properties
WARNING: The metadata
object returned in the response will have its keys in lowercase, even if they originally contained uppercase characters. This differs from the metadata keys returned by the listContainers
method of BlobServiceClient using the includeMetadata
option, which will retain their original casing.
function getProperties(options?: ContainerGetPropertiesOptions): Promise<ContainerGetPropertiesResponse>
Parameters Returns
Promise<ContainerGetPropertiesResponse>
listBlobsByHierarchy(string, ContainerListBlobsOptions)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}`);
}
}
function listBlobsByHierarchy(delimiter: string, options?: ContainerListBlobsOptions): PagedAsyncIterableIterator<({ kind: "prefix" } & BlobPrefix) | ({ kind: "blob" } & BlobItem), ContainerListBlobHierarchySegmentResponse, PageSettings>
Parameters
string
The character or string used to define the virtual hierarchy
ReturnsPagedAsyncIterableIterator<({ kind: "prefix" } & BlobPrefix) | ({ kind: "blob" } & BlobItem), ContainerListBlobHierarchySegmentResponse, PageSettings>
listBlobsFlat(ContainerListBlobsOptions)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}`);
}
}
function listBlobsFlat(options?: ContainerListBlobsOptions): PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse, PageSettings>
Parameters Returns
PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse, PageSettings>
An asyncIterableIterator that supports paging.
setAccessPolicy(PublicAccessType, SignedIdentifier[], ContainerSetAccessPolicyOptions)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.
See https://learn.microsoft.com/rest/api/storageservices/set-container-acl
function setAccessPolicy(access?: PublicAccessType, containerAcl?: SignedIdentifier[], options?: ContainerSetAccessPolicyOptions): Promise<ContainerSetAccessPolicyResponse>
Parameters
Array of elements each having a unique Id and details of the access policy.
ReturnsPromise<ContainerSetAccessPolicyResponse>
setMetadata(Metadata, ContainerSetMetadataOptions)Sets one or more user-defined name-value pairs for the specified container.
If no option provided, or no metadata defined in the parameter, the container metadata will be removed.
See https://learn.microsoft.com/rest/api/storageservices/set-container-metadata
function setMetadata(metadata?: Metadata, options?: ContainerSetMetadataOptions): Promise<ContainerSetMetadataResponse>
Parameters
Replace existing metadata with this value. If no value provided the existing metadata will be removed.
ReturnsPromise<ContainerSetMetadataResponse>
uploadBlockBlob(string, RequestBodyType, number, BlockBlobUploadOptions)Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use stageBlock and commitBlockList.
This is a non-parallel uploading method, please use uploadFile, uploadStream or uploadBrowserData for better performance with concurrency uploading.
See https://learn.microsoft.com/rest/api/storageservices/put-blob
function uploadBlockBlob(blobName: string, body: RequestBodyType, contentLength: number, options?: BlockBlobUploadOptions): Promise<{ blockBlobClient: BlockBlobClient, response: BlockBlobUploadResponse }>
Parameters
string
Name of the block blob to create or update.
Blob, string, ArrayBuffer, ArrayBufferView or a function which returns a new Readable stream whose offset is from data source beginning.
number
Length of body in bytes. Use Buffer.byteLength() to calculate body length for a string including non non-Base64/Hex-encoded characters.
ReturnsPromise<{ blockBlobClient: BlockBlobClient, response: BlockBlobUploadResponse }>
Block Blob upload response data and the corresponding BlockBlobClient instance.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4