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 Container Service 共用存取簽章 (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 回應中傳回的物件會以小寫顯示其索引鍵,即使原本包含大寫字元也一樣。 這與BlobServiceClientincludeMetadata 方法所 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 Container Service 共用存取簽章 (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 日期可能會失去精確度。 例如,新的 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

初始建議的租用識別碼。

傳回

用於管理容器租用的新 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 回應中傳回的物件會以小寫顯示其索引鍵,即使原本包含大寫字元也一樣。 這與BlobServiceClientincludeMetadata 方法所 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[]

每個元素的陣列都有唯一的識別碼和存取原則的詳細資料。

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 實例。