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

ContainerClient class

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

扩展

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 日期可能会丢失精度。 例如,新日期(“2018-12-31T03:44:23.8827891Z”)将获取“2018-12-31T03:44:23.882Z”。

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

getAccountInfo(ContainerGetAccountInfoOptions)

获取帐户信息操作返回指定帐户的 SKU 名称和帐户类型。 从版本 2018-03-28 开始,获取帐户信息操作适用于服务版本。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information

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 对象将具有小写形式的键,即使它们最初包含大写字符也是如此。 这不同于使用 includeMetadata 选项 BlobServiceClientlistContainers 方法返回的元数据键,该方法将保留其原始大小写。

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, RequestBodyType, 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(如“https://myaccount.blob.core.windows.net/mycontainer?sasString"),则可以追加 SAS。

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(如“https://myaccount.blob.core.windows.net/mycontainer?sasString"),则可以追加 SAS。

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>

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

getAccessPolicy(ContainerGetAccessPolicyOptions)

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

警告:分析 startOn 和 expiresOn 字符串时,JavaScript 日期可能会丢失精度。 例如,新日期(“2018-12-31T03:44:23.8827891Z”)将获取“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

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

返回

getAccountInfo(ContainerGetAccountInfoOptions)

获取帐户信息操作返回指定帐户的 SKU 名称和帐户类型。 从版本 2018-03-28 开始,获取帐户信息操作适用于服务版本。

请参阅 https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information

function getAccountInfo(options?: ContainerGetAccountInfoOptions): Promise<ContainerGetAccountInfoResponse>

参数

options
ContainerGetAccountInfoOptions

服务获取帐户信息操作的选项。

返回

服务获取帐户信息操作的响应数据。

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 对象将具有小写形式的键,即使它们最初包含大写字符也是如此。 这不同于使用 includeMetadata 选项 BlobServiceClientlistContainers 方法返回的元数据键,该方法将保留其原始大小写。

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, RequestBodyType, number, BlockBlobUploadOptions)

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

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

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

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

function uploadBlockBlob(blobName: string, body: RequestBodyType, 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 实例。