共用方式為


BlobServiceClient class

BlobServiceClient 代表 Azure 記憶體 Blob 服務的用戶端,可讓您操作 Blob 容器。

Extends

StorageClient

建構函式

BlobServiceClient(string, PipelineLike)

建立 BlobServiceClient 的實例。

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

建立 BlobServiceClient 的實例。

繼承的屬性

accountName
credential

例如 AnonymousCredential、StorageSharedKeyCredential 或任何來自 @azure/identity 套件的認證,以驗證對服務的要求。 您也可以提供實作 TokenCredential 介面的物件。 如果未指定,則會使用 AnonymousCredential。

url

編碼的 URL 字串值。

方法

createContainer(string, ContainerCreateOptions)

建立 Blob 容器。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container

deleteContainer(string, ContainerDeleteMethodOptions)

刪除 Blob 容器。

findBlobsByTags(string, ServiceFindBlobByTagsOptions)

傳回異步反覆運算器,以在指定的帳戶下尋找具有指定標籤的所有 Blob。

.byPage() 會傳回異步可迭代反覆運算器,以列出分頁中的 Blob。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties

使用 for await 語法的範例:

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

使用 iter.next()的範例:

let i = 1;
const iter = blobServiceClient.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 blobServiceClient.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 = blobServiceClient.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 = blobServiceClient
  .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}`);
  }
}
fromConnectionString(string, StoragePipelineOptions)

從連接字串建立 BlobServiceClient 的實例。

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

僅適用於使用共用密鑰認證建構的 BlobServiceClient。

根據傳入的用戶端屬性和參數,產生 Blob 帳戶共用存取簽章 (SAS) URI。 SAS 是由客戶端的共用金鑰認證所簽署。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

僅適用於使用共用密鑰認證建構的 BlobServiceClient。

根據傳入的用戶端屬性和參數,產生要簽署 Blob 帳戶共用存取簽章 (SAS) URI 的字串。 SAS 是由客戶端的共用金鑰認證所簽署。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas

getAccountInfo(ServiceGetAccountInfoOptions)

取得帳戶資訊作業會傳回指定帳戶的 SKU 名稱和帳戶種類。 從 2018-03-28 版開始的服務版本,即可取得帳戶資訊作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information

getBlobBatchClient()

建立 BlobBatchClient 物件來執行批次作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch

getContainerClient(string)

建立 ContainerClient 物件

getProperties(ServiceGetPropertiesOptions)

取得記憶體帳戶 Blob 服務的屬性,包括記憶體分析和 CORS(跨原始來源資源分享)規則的屬性。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties

getStatistics(ServiceGetStatisticsOptions)

擷取與 Blob 服務複寫相關的統計數據。 只有在記憶體帳戶啟用讀取許可權異地備援複寫時,才能在次要位置端點上使用。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats

getUserDelegationKey(Date, Date, ServiceGetUserDelegationKeyOptions)

僅適用於使用 BEARER 令牌驗證 (TokenCredential) 時。

擷取 Blob 服務的使用者委派密鑰。 使用持有人令牌驗證時,這隻是有效的作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-user-delegation-key

listContainers(ServiceListContainersOptions)

傳回異步反覆運算器,以列出指定帳戶下的所有容器。

.byPage() 會傳回可同步反覆運算器,以列出頁面中的容器。

使用 for await 語法的範例:

let i = 1;
for await (const container of blobServiceClient.listContainers()) {
  console.log(`Container ${i++}: ${container.name}`);
}

使用 iter.next()的範例:

let i = 1;
const iter = blobServiceClient.listContainers();
let containerItem = await iter.next();
while (!containerItem.done) {
  console.log(`Container ${i++}: ${containerItem.value.name}`);
  containerItem = await iter.next();
}

使用 byPage()的範例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of blobServiceClient.listContainers().byPage({ maxPageSize: 20 })) {
  if (response.containerItems) {
    for (const container of response.containerItems) {
      console.log(`Container ${i++}: ${container.name}`);
    }
  }
}

使用分頁搭配標記的範例:

let i = 1;
let iterator = blobServiceClient.listContainers().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

// Prints 2 container names
if (response.containerItems) {
  for (const container of response.containerItems) {
    console.log(`Container ${i++}: ${container.name}`);
  }
}

// Gets next marker
let marker = response.continuationToken;
// Passing next marker as continuationToken
iterator = blobServiceClient
  .listContainers()
  .byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

// Prints 10 container names
if (response.containerItems) {
  for (const container of response.containerItems) {
     console.log(`Container ${i++}: ${container.name}`);
  }
}
setProperties(BlobServiceProperties, ServiceSetPropertiesOptions)

設定記憶體帳戶 Blob 服務端點的屬性,包括記憶體分析、CORS(跨原始來源資源分享)規則和虛刪除設定的屬性。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties

undeleteContainer(string, string, ServiceUndeleteContainerOptions)

還原先前已刪除的 Blob 容器。 只有在針對與容器相關聯的記憶體帳戶啟用容器虛刪除時,此 API 才會運作。

建構函式詳細資料

BlobServiceClient(string, PipelineLike)

建立 BlobServiceClient 的實例。

new BlobServiceClient(url: string, pipeline: PipelineLike)

參數

url

string

指向 Azure 記憶體 Blob 服務的用戶端字串,例如 「https://myaccount.blob.core.windows.net"。 如果使用 AnonymousCredential,則可以附加 SAS,例如 “https://myaccount.blob.core.windows.net?sasString"。

pipeline
PipelineLike

呼叫 newPipeline() 以建立預設管線,或提供自定義管線。

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

建立 BlobServiceClient 的實例。

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

參數

url

string

指向 Azure 記憶體 Blob 服務的用戶端字串,例如 「https://myaccount.blob.core.windows.net"。 如果使用 AnonymousCredential,則可以附加 SAS,例如 “https://myaccount.blob.core.windows.net?sasString"。

credential

StorageSharedKeyCredential | AnonymousCredential | TokenCredential

例如 AnonymousCredential、StorageSharedKeyCredential 或任何來自 @azure/identity 套件的認證,以驗證對服務的要求。 您也可以提供實作 TokenCredential 介面的物件。 如果未指定,則會使用 AnonymousCredential。

options
StoragePipelineOptions

自選。 設定 HTTP 管線的選項。

@azure/identity使用 DefaultAzureCredential 的範例:

const account = "<storage account name>";

const defaultAzureCredential = new DefaultAzureCredential();

const blobServiceClient = new BlobServiceClient(
  `https://${account}.blob.core.windows.net`,
  defaultAzureCredential
);

使用帳號名稱/金鑰的範例:

const account = "<storage account name>"
const sharedKeyCredential = new StorageSharedKeyCredential(account, "<account key>");

const blobServiceClient = new BlobServiceClient(
  `https://${account}.blob.core.windows.net`,
  sharedKeyCredential
);

繼承的屬性詳細資料

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

方法詳細資料

createContainer(string, ContainerCreateOptions)

建立 Blob 容器。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-container

function createContainer(containerName: string, options?: ContainerCreateOptions): Promise<{ containerClient: ContainerClient, containerCreateResponse: ContainerCreateResponse }>

參數

containerName

string

要建立的容器名稱。

options
ContainerCreateOptions

設定容器建立作業的選項。

傳回

Promise<{ containerClient: ContainerClient, containerCreateResponse: ContainerCreateResponse }>

容器建立響應和對應的容器用戶端。

deleteContainer(string, ContainerDeleteMethodOptions)

刪除 Blob 容器。

function deleteContainer(containerName: string, options?: ContainerDeleteMethodOptions): Promise<ContainerDeleteResponse>

參數

containerName

string

要刪除的容器名稱。

options
ContainerDeleteMethodOptions

設定容器刪除作業的選項。

傳回

容器刪除回應。

findBlobsByTags(string, ServiceFindBlobByTagsOptions)

傳回異步反覆運算器,以在指定的帳戶下尋找具有指定標籤的所有 Blob。

.byPage() 會傳回異步可迭代反覆運算器,以列出分頁中的 Blob。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties

使用 for await 語法的範例:

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

使用 iter.next()的範例:

let i = 1;
const iter = blobServiceClient.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 blobServiceClient.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 = blobServiceClient.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 = blobServiceClient
  .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?: ServiceFindBlobByTagsOptions): PagedAsyncIterableIterator<FilterBlobItem, ServiceFindBlobsByTagsSegmentResponse, PageSettings>

參數

tagFilterSqlExpression

string

where 參數可讓呼叫端查詢標記符合指定表達式的 Blob。 指定的表達式必須評估為 true,才能在結果中傳回 Blob。 [OData - ABNF] 篩選語法規則會定義 where query 參數值的正式文法;不過,Blob 服務只支援 OData 篩選語法的子集。

options
ServiceFindBlobByTagsOptions

依標記尋找 Blob 的選項。

傳回

fromConnectionString(string, StoragePipelineOptions)

從連接字串建立 BlobServiceClient 的實例。

static function fromConnectionString(connectionString: string, options?: StoragePipelineOptions): BlobServiceClient

參數

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

options
StoragePipelineOptions

自選。 設定 HTTP 管線的選項。

傳回

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

僅適用於使用共用密鑰認證建構的 BlobServiceClient。

根據傳入的用戶端屬性和參數,產生 Blob 帳戶共用存取簽章 (SAS) URI。 SAS 是由客戶端的共用金鑰認證所簽署。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas

function generateAccountSasUrl(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): string

參數

expiresOn

Date

自選。 共用存取簽章失效的時間。 如果未提供,則預設為1小時後。

permissions
AccountSASPermissions

指定要與 SAS 相關聯的許可權清單。

resourceTypes

string

指定與共用存取簽章相關聯的資源類型。

options
ServiceGenerateAccountSasUrlOptions

選擇性參數。

傳回

string

帳戶 SAS URI,其中包含此用戶端所代表資源的 URI,後面接著產生的 SAS 令牌。

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

僅適用於使用共用密鑰認證建構的 BlobServiceClient。

根據傳入的用戶端屬性和參數,產生要簽署 Blob 帳戶共用存取簽章 (SAS) URI 的字串。 SAS 是由客戶端的共用金鑰認證所簽署。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas

function generateSasStringToSign(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): string

參數

expiresOn

Date

自選。 共用存取簽章失效的時間。 如果未提供,則預設為1小時後。

permissions
AccountSASPermissions

指定要與 SAS 相關聯的許可權清單。

resourceTypes

string

指定與共用存取簽章相關聯的資源類型。

options
ServiceGenerateAccountSasUrlOptions

選擇性參數。

傳回

string

帳戶 SAS URI,其中包含此用戶端所代表資源的 URI,後面接著產生的 SAS 令牌。

getAccountInfo(ServiceGetAccountInfoOptions)

取得帳戶資訊作業會傳回指定帳戶的 SKU 名稱和帳戶種類。 從 2018-03-28 版開始的服務版本,即可取得帳戶資訊作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information

function getAccountInfo(options?: ServiceGetAccountInfoOptions): Promise<ServiceGetAccountInfoResponse>

參數

options
ServiceGetAccountInfoOptions

服務取得帳戶資訊作業的選項。

傳回

服務取得帳戶資訊作業的響應數據。

getBlobBatchClient()

建立 BlobBatchClient 物件來執行批次作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/blob-batch

function getBlobBatchClient(): BlobBatchClient

傳回

此服務的新 BlobBatchClient 物件。

getContainerClient(string)

建立 ContainerClient 物件

function getContainerClient(containerName: string): ContainerClient

參數

containerName

string

容器名稱

傳回

指定容器名稱的新 ContainerClient 物件。

範例用法:

const containerClient = blobServiceClient.getContainerClient("<container name>");

getProperties(ServiceGetPropertiesOptions)

取得記憶體帳戶 Blob 服務的屬性,包括記憶體分析和 CORS(跨原始來源資源分享)規則的屬性。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties

function getProperties(options?: ServiceGetPropertiesOptions): Promise<ServiceGetPropertiesResponse>

參數

options
ServiceGetPropertiesOptions

服務取得屬性作業的選項。

傳回

服務取得屬性作業的響應數據。

getStatistics(ServiceGetStatisticsOptions)

擷取與 Blob 服務複寫相關的統計數據。 只有在記憶體帳戶啟用讀取許可權異地備援複寫時,才能在次要位置端點上使用。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats

function getStatistics(options?: ServiceGetStatisticsOptions): Promise<ServiceGetStatisticsResponse>

參數

options
ServiceGetStatisticsOptions

服務取得統計數據作業的選項。

傳回

服務取得統計數據作業的響應數據。

getUserDelegationKey(Date, Date, ServiceGetUserDelegationKeyOptions)

僅適用於使用 BEARER 令牌驗證 (TokenCredential) 時。

擷取 Blob 服務的使用者委派密鑰。 使用持有人令牌驗證時,這隻是有效的作業。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-user-delegation-key

function getUserDelegationKey(startsOn: Date, expiresOn: Date, options?: ServiceGetUserDelegationKeyOptions): Promise<ServiceGetUserDelegationKeyResponse>

參數

startsOn

Date

使用者委派 SAS 的開始時間。 必須在目前時間的 7 天內

expiresOn

Date

使用者委派 SAS 的結束時間。 必須在目前時間的 7 天內

傳回

listContainers(ServiceListContainersOptions)

傳回異步反覆運算器,以列出指定帳戶下的所有容器。

.byPage() 會傳回可同步反覆運算器,以列出頁面中的容器。

使用 for await 語法的範例:

let i = 1;
for await (const container of blobServiceClient.listContainers()) {
  console.log(`Container ${i++}: ${container.name}`);
}

使用 iter.next()的範例:

let i = 1;
const iter = blobServiceClient.listContainers();
let containerItem = await iter.next();
while (!containerItem.done) {
  console.log(`Container ${i++}: ${containerItem.value.name}`);
  containerItem = await iter.next();
}

使用 byPage()的範例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of blobServiceClient.listContainers().byPage({ maxPageSize: 20 })) {
  if (response.containerItems) {
    for (const container of response.containerItems) {
      console.log(`Container ${i++}: ${container.name}`);
    }
  }
}

使用分頁搭配標記的範例:

let i = 1;
let iterator = blobServiceClient.listContainers().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

// Prints 2 container names
if (response.containerItems) {
  for (const container of response.containerItems) {
    console.log(`Container ${i++}: ${container.name}`);
  }
}

// Gets next marker
let marker = response.continuationToken;
// Passing next marker as continuationToken
iterator = blobServiceClient
  .listContainers()
  .byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

// Prints 10 container names
if (response.containerItems) {
  for (const container of response.containerItems) {
     console.log(`Container ${i++}: ${container.name}`);
  }
}
function listContainers(options?: ServiceListContainersOptions): PagedAsyncIterableIterator<ContainerItem, ServiceListContainersSegmentResponse, PageSettings>

參數

options
ServiceListContainersOptions

列出容器的選項。

傳回

支援分頁的 asyncIterableIterator。

setProperties(BlobServiceProperties, ServiceSetPropertiesOptions)

設定記憶體帳戶 Blob 服務端點的屬性,包括記憶體分析、CORS(跨原始來源資源分享)規則和虛刪除設定的屬性。

請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties

function setProperties(properties: BlobServiceProperties, options?: ServiceSetPropertiesOptions): Promise<ServiceSetPropertiesResponse>

參數

options
ServiceSetPropertiesOptions

服務集屬性作業的選項。

傳回

服務集屬性作業的響應數據。

undeleteContainer(string, string, ServiceUndeleteContainerOptions)

還原先前已刪除的 Blob 容器。 只有在針對與容器相關聯的記憶體帳戶啟用容器虛刪除時,此 API 才會運作。

function undeleteContainer(deletedContainerName: string, deletedContainerVersion: string, options?: ServiceUndeleteContainerOptions): Promise<{ containerClient: ContainerClient, containerUndeleteResponse: ContainerUndeleteResponse }>

參數

deletedContainerName

string

先前已刪除容器的名稱。

deletedContainerVersion

string

先前刪除的容器版本,用來唯一識別已刪除的容器。

options
ServiceUndeleteContainerOptions

設定容器還原作業的選項。

傳回

Promise<{ containerClient: ContainerClient, containerUndeleteResponse: ContainerUndeleteResponse }>

容器刪除回應。