你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

ContainerClient class

ContainerClient 表示 Azure 存储容器的 URL,允许你操作其 blob。

Extends

StorageClient

构造函数

ContainerClient(string, PipelineLike)

创建 ContainerClient 的实例。 此方法接受指向容器的 URL。 编码的 URL 字符串不会转义两次,只会转义 URL 路径中的特殊字符。 Blob 名称是否包含 ? 或 % blob 名称必须在 URL 中编码。

ContainerClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

创建 ContainerClient 的实例。 此方法接受指向容器的 URL。 编码的 URL 字符串不会转义两次,只会转义 URL 路径中的特殊字符。 Blob 名称是否包含 ? 或 % blob 名称必须在 URL 中编码。

ContainerClient(string, string, StoragePipelineOptions)

创建 ContainerClient 的实例。

属性

containerName

容器的名称。

继承属性

accountName
credential

例如 AnonymousCredential、StorageSharedKeyCredential 或包中的任何 @azure/identity 凭据,用于对服务的请求进行身份验证。 还可以提供实现 TokenCredential 接口的对象。 如果未指定,则使用 AnonymousCredential。

url

编码的 URL 字符串值。

方法

create(ContainerCreateOptions)

在指定的帐户下创建新容器。 如果已存在同名的容器,操作将失败。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container 命名规则:请参阅 https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata

createIfNotExists(ContainerCreateOptions)

在指定的帐户下创建新容器。 如果同名的容器已存在,则不会更改该容器。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container 命名规则:请参阅 https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata

delete(ContainerDeleteMethodOptions)

标记要删除的指定容器。 在稍后的垃圾回收期间,将删除该容器及其包含的任何 Blob。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container

deleteBlob(string, ContainerDeleteBlobOptions)

标记要删除的指定 Blob 或快照。 该 Blob 将在稍后的垃圾回收期间删除。 请注意,要删除 Blob,必须删除其所有快照。 可以使用删除 Blob 操作同时删除这两者。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob

deleteIfExists(ContainerDeleteMethodOptions)

将指定的容器标记为删除(如果存在)。 在稍后的垃圾回收期间,将删除该容器及其包含的任何 Blob。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container

exists(ContainerExistsOptions)

如果此客户端表示的 Azure 容器资源存在,则返回 true;否则为 false。

注意:请谨慎使用此函数,因为现有容器可能会被其他客户端或应用程序删除。 反之亦然,此函数完成后,其他客户端或应用程序可能会添加同名的新容器。

findBlobsByTags(string, ContainerFindBlobByTagsOptions)

返回一个异步可迭代器,用于查找指定容器下具有指定标记的所有 blob。

.byPage () 返回一个异步可迭代器,用于列出页中的 Blob。

使用 for await 语法的示例:

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

使用 iter.next() 的示例:

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

使用 byPage() 的示例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of containerClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 20 })) {
  if (response.blobs) {
    for (const blob of response.blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
    }
  }
}

使用标记分页的示例:

let 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 blob names
if (response.blobs) {
  for (const blob of response.blobs) {
     console.log(`Blob ${i++}: ${blob.name}`);
  }
}
generateSasUrl(ContainerGenerateSasUrlOptions)

仅适用于使用共享密钥凭据构造的 ContainerClient。

根据传入的客户端属性和参数生成 Blob 容器服务共享访问签名 (SAS) URI。 SAS 由客户端的共享密钥凭据签名。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas

getAccessPolicy(ContainerGetAccessPolicyOptions)

获取指定容器的权限。 这些权限指示是否可以公开访问容器数据。

警告:分析 startOn 和 expiresOn 字符串时,JavaScript 日期可能会丢失精度。 例如,新的 Date (“2018-12-31T03:44:23.8827891Z”) .toISOString () 将获取“2018-12-31T03:44:23.882Z”。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-acl

getAppendBlobClient(string)

创建 AppendBlobClient

getBlobBatchClient()

创建 BlobBatchClient 对象以执行批处理操作。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch

getBlobClient(string)

创建 BlobClient

getBlobLeaseClient(string)

获取一个 BlobLeaseClient ,用于管理容器上的租约。

getBlockBlobClient(string)

创建 BlockBlobClient

getPageBlobClient(string)

创建 PageBlobClient

getProperties(ContainerGetPropertiesOptions)

返回指定容器的所有用户定义的元数据和系统属性。 返回的数据不包含该容器的 Blob 列表。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-properties

警告:响应 metadata 中返回的对象将具有小写的键,即使它们最初包含大写字符。 这不同于 BlobServiceClient 方法使用 includeMetadata 选项返回listContainers的元数据键,后者将保留其原始大小写。

listBlobsByHierarchy(string, ContainerListBlobsOptions)

返回一个异步可迭代器,用于按层次结构列出所有 Blob。 在指定帐户下。

.byPage () 返回一个异步可迭代器,用于按页中的层次结构列出 Blob。

使用 for await 语法的示例:

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

使用 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}`);
  }
  entity = await iter.next();
}

使用 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}`);
  }
}

使用具有最大页面大小的分页的示例:

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}`);
  }
}
listBlobsFlat(ContainerListBlobsOptions)

返回一个异步可迭代器,用于列出指定帐户下的所有 Blob。

.byPage () 返回一个异步可迭代器,用于列出页中的 Blob。

使用 for await 语法的示例:

// 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}`);
}

使用 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();
}

使用 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}`);
  }
}

使用标记分页的示例:

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}`);
}
setAccessPolicy(PublicAccessType, SignedIdentifier[], ContainerSetAccessPolicyOptions)

设置指定容器的权限。 这些权限指示是否可以公开访问容器中的 Blob。

在设置容器的权限时,将替换现有的权限。 如果未提供访问权限或 containerAcl,则会删除现有的容器 ACL。

建立容器的存储访问策略时,它可能最多需要 30 秒才能生效。 在此期间,与该存储访问策略关联的共享访问签名将失败,状态代码为 403(禁止访问),直到访问策略成为活动的。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-acl

setMetadata(Metadata, ContainerSetMetadataOptions)

为指定的容器设置一个或多个用户定义的名称-值对。

如果未提供选项,或者在 参数中未定义任何元数据,则将删除容器元数据。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-metadata

uploadBlockBlob(string, HttpRequestBody, number, BlockBlobUploadOptions)

创建新的块 Blob,或更新现有块 Blob 的内容。

更新现有块 Blob 会覆盖该 Blob 的所有现有元数据。 不支持部分更新;现有 Blob 的内容将被新内容覆盖。 若要执行块 Blob 的部分更新,请使用 stageBlockcommitBlockList

这是一种非并行上传方法,请使用 uploadFileuploadStreamuploadBrowserData 来提高并发上传的性能。

请参见https://docs.microsoft.com/rest/api/storageservices/put-blob

构造函数详细信息

ContainerClient(string, PipelineLike)

创建 ContainerClient 的实例。 此方法接受指向容器的 URL。 编码的 URL 字符串不会转义两次,只会转义 URL 路径中的特殊字符。 Blob 名称是否包含 ? 或 % blob 名称必须在 URL 中编码。

new ContainerClient(url: string, pipeline: PipelineLike)

参数

url

string

指向 Azure 存储容器的 URL 字符串,例如“https://myaccount.blob.core.windows.net/mycontainer"”。 如果使用 AnonymousCredential,则可以追加 SAS,例如“https://myaccount.blob.core.windows.net/mycontainer?sasString"”。

pipeline
PipelineLike

调用 newPipeline () 以创建默认管道或提供自定义管道。

ContainerClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

创建 ContainerClient 的实例。 此方法接受指向容器的 URL。 编码的 URL 字符串不会转义两次,只会转义 URL 路径中的特殊字符。 Blob 名称是否包含 ? 或 % blob 名称必须在 URL 中编码。

new ContainerClient(url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)

参数

url

string

指向 Azure 存储容器的 URL 字符串,例如“https://myaccount.blob.core.windows.net/mycontainer"”。 如果使用 AnonymousCredential,则可以追加 SAS,例如“https://myaccount.blob.core.windows.net/mycontainer?sasString"”。

credential

StorageSharedKeyCredential | AnonymousCredential | TokenCredential

例如 AnonymousCredential、StorageSharedKeyCredential 或包中的任何 @azure/identity 凭据,用于对服务的请求进行身份验证。 还可以提供实现 TokenCredential 接口的对象。 如果未指定,则使用 AnonymousCredential。

options
StoragePipelineOptions

可选。 用于配置 HTTP 管道的选项。

ContainerClient(string, string, StoragePipelineOptions)

创建 ContainerClient 的实例。

new ContainerClient(connectionString: string, containerName: string, options?: StoragePipelineOptions)

参数

connectionString

string

Azure 存储帐户的帐户连接字符串或 SAS 连接字符串。 [ 注意 - 帐户连接字符串只能在NODE.JS运行时中使用。 ] 帐户连接字符串示例 -DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS 连接字符串示例 - 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

容器名称。

options
StoragePipelineOptions

可选。 用于配置 HTTP 管道的选项。

属性详细信息

containerName

容器的名称。

string containerName

属性值

string

继承属性详细信息

accountName

accountName: string

属性值

string

继承自 StorageClient.accountName

credential

例如 AnonymousCredential、StorageSharedKeyCredential 或包中的任何 @azure/identity 凭据,用于对服务的请求进行身份验证。 还可以提供实现 TokenCredential 接口的对象。 如果未指定,则使用 AnonymousCredential。

credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential

属性值

继承自 StorageClient.credential

url

编码的 URL 字符串值。

url: string

属性值

string

继承自 StorageClient.url

方法详细信息

create(ContainerCreateOptions)

在指定的帐户下创建新容器。 如果已存在同名的容器,操作将失败。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container 命名规则:请参阅 https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata

function create(options?: ContainerCreateOptions): Promise<ContainerCreateResponse>

参数

options
ContainerCreateOptions

容器创建操作的选项。

用法示例:

const containerClient = blobServiceClient.getContainerClient("<container name>");
const createContainerResponse = await containerClient.create();
console.log("Container was created successfully", createContainerResponse.requestId);

返回

createIfNotExists(ContainerCreateOptions)

在指定的帐户下创建新容器。 如果同名的容器已存在,则不会更改该容器。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container 命名规则:请参阅 https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata

function createIfNotExists(options?: ContainerCreateOptions): Promise<ContainerCreateIfNotExistsResponse>

参数

返回

delete(ContainerDeleteMethodOptions)

标记要删除的指定容器。 在稍后的垃圾回收期间,将删除该容器及其包含的任何 Blob。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container

function delete(options?: ContainerDeleteMethodOptions): Promise<ContainerDeleteResponse>

参数

options
ContainerDeleteMethodOptions

容器删除操作的选项。

返回

deleteBlob(string, ContainerDeleteBlobOptions)

标记要删除的指定 Blob 或快照。 该 Blob 将在稍后的垃圾回收期间删除。 请注意,要删除 Blob,必须删除其所有快照。 可以使用删除 Blob 操作同时删除这两者。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob

function deleteBlob(blobName: string, options?: ContainerDeleteBlobOptions): Promise<BlobDeleteResponse>

参数

blobName

string

options
ContainerDeleteBlobOptions

Blob 删除操作的选项。

返回

阻止 Blob 删除响应数据。

deleteIfExists(ContainerDeleteMethodOptions)

将指定的容器标记为删除(如果存在)。 在稍后的垃圾回收期间,将删除该容器及其包含的任何 Blob。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container

function deleteIfExists(options?: ContainerDeleteMethodOptions): Promise<ContainerDeleteIfExistsResponse>

参数

options
ContainerDeleteMethodOptions

容器删除操作的选项。

返回

exists(ContainerExistsOptions)

如果此客户端表示的 Azure 容器资源存在,则返回 true;否则为 false。

注意:请谨慎使用此函数,因为现有容器可能会被其他客户端或应用程序删除。 反之亦然,此函数完成后,其他客户端或应用程序可能会添加同名的新容器。

function exists(options?: ContainerExistsOptions): Promise<boolean>

参数

返回

Promise<boolean>

findBlobsByTags(string, ContainerFindBlobByTagsOptions)

返回一个异步可迭代器,用于查找指定容器下具有指定标记的所有 blob。

.byPage () 返回一个异步可迭代器,用于列出页中的 Blob。

使用 for await 语法的示例:

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

使用 iter.next() 的示例:

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

使用 byPage() 的示例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of containerClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 20 })) {
  if (response.blobs) {
    for (const blob of response.blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
    }
  }
}

使用标记分页的示例:

let 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 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>

参数

tagFilterSqlExpression

string

where 参数使调用方能够查询其标记与给定表达式匹配的 blob。 给定表达式的计算结果必须为 true,才能在结果中返回 Blob。 [OData - ABNF] 筛选器语法规则定义 where 查询参数的值的正式语法;但是,Blob 服务中仅支持一部分 OData 筛选器语法。

options
ContainerFindBlobByTagsOptions

用于按标记查找 Blob 的选项。

返回

generateSasUrl(ContainerGenerateSasUrlOptions)

仅适用于使用共享密钥凭据构造的 ContainerClient。

根据传入的客户端属性和参数生成 Blob 容器服务共享访问签名 (SAS) URI。 SAS 由客户端的共享密钥凭据签名。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas

function generateSasUrl(options: ContainerGenerateSasUrlOptions): Promise<string>

参数

options
ContainerGenerateSasUrlOptions

可选参数。

返回

Promise<string>

SAS URI 由此客户端表示的资源的 URI 组成,后跟生成的 SAS 令牌。

getAccessPolicy(ContainerGetAccessPolicyOptions)

获取指定容器的权限。 这些权限指示是否可以公开访问容器数据。

警告:分析 startOn 和 expiresOn 字符串时,JavaScript 日期可能会丢失精度。 例如,新的 Date (“2018-12-31T03:44:23.8827891Z”) .toISOString () 将获取“2018-12-31T03:44:23.882Z”。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-acl

function getAccessPolicy(options?: ContainerGetAccessPolicyOptions): Promise<ContainerGetAccessPolicyResponse>

参数

options
ContainerGetAccessPolicyOptions

容器获取访问策略操作的选项。

返回

getAppendBlobClient(string)

创建 AppendBlobClient

function getAppendBlobClient(blobName: string): AppendBlobClient

参数

blobName

string

追加 Blob 名称

返回

getBlobBatchClient()

创建 BlobBatchClient 对象以执行批处理操作。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch

function getBlobBatchClient(): BlobBatchClient

返回

此容器的新 BlobBatchClient 对象。

getBlobClient(string)

创建 BlobClient

function getBlobClient(blobName: string): BlobClient

参数

blobName

string

Blob 名称

返回

给定 Blob 名称的新 BlobClient 对象。

getBlobLeaseClient(string)

获取一个 BlobLeaseClient ,用于管理容器上的租约。

function getBlobLeaseClient(proposeLeaseId?: string): BlobLeaseClient

参数

proposeLeaseId

string

初始建议租约 ID。

返回

一个新的 BlobLeaseClient 对象,用于管理容器上的租约。

getBlockBlobClient(string)

创建 BlockBlobClient

function getBlockBlobClient(blobName: string): BlockBlobClient

参数

blobName

string

块 Blob 名称

用法示例:

const content = "Hello world!";

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

返回

getPageBlobClient(string)

创建 PageBlobClient

function getPageBlobClient(blobName: string): PageBlobClient

参数

blobName

string

页 Blob 名称

返回

getProperties(ContainerGetPropertiesOptions)

返回指定容器的所有用户定义的元数据和系统属性。 返回的数据不包含该容器的 Blob 列表。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-properties

警告:响应 metadata 中返回的对象将具有小写的键,即使它们最初包含大写字符。 这不同于 BlobServiceClient 方法使用 includeMetadata 选项返回listContainers的元数据键,后者将保留其原始大小写。

function getProperties(options?: ContainerGetPropertiesOptions): Promise<ContainerGetPropertiesResponse>

参数

options
ContainerGetPropertiesOptions

容器获取属性操作的选项。

返回

listBlobsByHierarchy(string, ContainerListBlobsOptions)

返回一个异步可迭代器,用于按层次结构列出所有 Blob。 在指定帐户下。

.byPage () 返回一个异步可迭代器,用于按页中的层次结构列出 Blob。

使用 for await 语法的示例:

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

使用 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}`);
  }
  entity = await iter.next();
}

使用 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}`);
  }
}

使用具有最大页面大小的分页的示例:

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}`);
  }
}
function listBlobsByHierarchy(delimiter: string, options?: ContainerListBlobsOptions): PagedAsyncIterableIterator<({ kind: "prefix" } & BlobPrefix) | ({ kind: "blob" } & BlobItem), ContainerListBlobHierarchySegmentResponse, PageSettings>

参数

delimiter

string

用于定义虚拟层次结构的字符或字符串

options
ContainerListBlobsOptions

用于列出 Blob 操作的选项。

返回

listBlobsFlat(ContainerListBlobsOptions)

返回一个异步可迭代器,用于列出指定帐户下的所有 Blob。

.byPage () 返回一个异步可迭代器,用于列出页中的 Blob。

使用 for await 语法的示例:

// 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}`);
}

使用 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();
}

使用 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}`);
  }
}

使用标记分页的示例:

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}`);
}
function listBlobsFlat(options?: ContainerListBlobsOptions): PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse, PageSettings>

参数

options
ContainerListBlobsOptions

用于列出 Blob 的选项。

返回

支持分页的 asyncIterableIterator。

setAccessPolicy(PublicAccessType, SignedIdentifier[], ContainerSetAccessPolicyOptions)

设置指定容器的权限。 这些权限指示是否可以公开访问容器中的 Blob。

在设置容器的权限时,将替换现有的权限。 如果未提供访问权限或 containerAcl,则会删除现有的容器 ACL。

建立容器的存储访问策略时,它可能最多需要 30 秒才能生效。 在此期间,与该存储访问策略关联的共享访问签名将失败,状态代码为 403(禁止访问),直到访问策略成为活动的。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-acl

function setAccessPolicy(access?: PublicAccessType, containerAcl?: SignedIdentifier[], options?: ContainerSetAccessPolicyOptions): Promise<ContainerSetAccessPolicyResponse>

参数

access
PublicAccessType

对容器中数据的公共访问级别。

containerAcl

SignedIdentifier[]

每个元素具有唯一的 ID 和访问策略的详细信息的数组。

options
ContainerSetAccessPolicyOptions

容器设置访问策略操作的选项。

返回

setMetadata(Metadata, ContainerSetMetadataOptions)

为指定的容器设置一个或多个用户定义的名称-值对。

如果未提供选项,或者在 参数中未定义任何元数据,则将删除容器元数据。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-metadata

function setMetadata(metadata?: Metadata, options?: ContainerSetMetadataOptions): Promise<ContainerSetMetadataResponse>

参数

metadata
Metadata

将现有元数据替换为此值。 如果未提供任何值,则将删除现有元数据。

options
ContainerSetMetadataOptions

容器设置元数据操作的选项。

返回

uploadBlockBlob(string, HttpRequestBody, number, BlockBlobUploadOptions)

创建新的块 Blob,或更新现有块 Blob 的内容。

更新现有块 Blob 会覆盖该 Blob 的所有现有元数据。 不支持部分更新;现有 Blob 的内容将被新内容覆盖。 若要执行块 Blob 的部分更新,请使用 stageBlockcommitBlockList

这是一种非并行上传方法,请使用 uploadFileuploadStreamuploadBrowserData 来提高并发上传的性能。

请参见https://docs.microsoft.com/rest/api/storageservices/put-blob

function uploadBlockBlob(blobName: string, body: HttpRequestBody, contentLength: number, options?: BlockBlobUploadOptions): Promise<{ blockBlobClient: BlockBlobClient, response: BlockBlobUploadResponse }>

参数

blobName

string

要创建或更新的块 Blob 的名称。

body
HttpRequestBody

Blob、字符串、ArrayBuffer、ArrayBufferView 或函数,该函数返回新的可读流,其偏移量从数据源开始。

contentLength

number

正文的长度(以字节为单位)。 使用 Buffer.byteLength () 计算字符串的正文长度,包括非 Base64/Hex 编码字符。

options
BlockBlobUploadOptions

用于配置块 Blob 上传操作的选项。

返回

Promise<{ blockBlobClient: BlockBlobClient, response: BlockBlobUploadResponse }>

块 Blob 上传响应数据和相应的 BlockBlobClient 实例。