共用方式為


ShareServiceClient class

ShareServiceClient 代表 Azure 記憶體檔案服務的 URL,可讓您作檔案共用。

Extends

StorageClient

建構函式

ShareServiceClient(string, Credential_2 | TokenCredential, ShareClientOptions)

建立 ShareServiceClient 的實例。

ShareServiceClient(string, Pipeline, ShareClientConfig)

建立 ShareServiceClient 的實例。

繼承的屬性

accountName
url

URL 字串值。

方法

createShare(string, ShareCreateOptions)

建立共用。

deleteShare(string, ShareDeleteMethodOptions)

刪除共用。

fromConnectionString(string, ShareClientOptions)

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

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

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

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

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

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

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

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

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

getProperties(ServiceGetPropertiesOptions)

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

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

getShareClient(string)

建立 ShareClient 物件。

listShares(ServiceListSharesOptions)

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

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

使用 for await 語法的範例:

let i = 1;
for await (const share of serviceClient.listShares()) {
  console.log(`Share ${i++}: ${share.name}`);
}

使用 iter.next()的範例:

let i = 1;
let iter = serviceClient.listShares();
let shareItem = await iter.next();
while (!shareItem.done) {
  console.log(`Share ${i++}: ${shareItem.value.name}`);
  shareItem = await iter.next();
}

使用 byPage()的範例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of serviceClient.listShares().byPage({ maxPageSize: 20 })) {
  if (response.shareItems) {
   for (const share of response.shareItems) {
       console.log(`Share ${i++}: ${share.name}`);
    }
  }
}

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

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

// Prints 2 share names
if (response.shareItems) {
  for (const share of response.shareItems) {
    console.log(`Share ${i++}: ${share.name}`);
  }
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = serviceClient.listShares().byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

// Prints 10 share names
if (response.shareItems) {
  for (const share of response.shareItems) {
    console.log(`Share ${i++}: ${share.name}`);
  }
}
setProperties(FileServiceProperties, ServiceSetPropertiesOptions)

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

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

undeleteShare(string, string, ServiceUndeleteShareOptions)

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

建構函式詳細資料

ShareServiceClient(string, Credential_2 | TokenCredential, ShareClientOptions)

建立 ShareServiceClient 的實例。

new ShareServiceClient(url: string, credential?: Credential_2 | TokenCredential, options?: ShareClientOptions)

參數

url

string

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

credential

Credential | TokenCredential

例如 AnonymousCredential、StorageSharedKeyCredential 或 TokenCredential,如果未指定,則會使用 AnonymousCredential。

options
ShareClientOptions

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

ShareServiceClient(string, Pipeline, ShareClientConfig)

建立 ShareServiceClient 的實例。

new ShareServiceClient(url: string, pipeline: Pipeline, options?: ShareClientConfig)

參數

url

string

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

pipeline
Pipeline

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

options
ShareClientConfig

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

繼承的屬性詳細資料

accountName

accountName: string

屬性值

string

繼承自 StorageClient.accountName

url

URL 字串值。

url: string

屬性值

string

繼承自 StorageClient.url

方法詳細資料

createShare(string, ShareCreateOptions)

建立共用。

function createShare(shareName: string, options?: ShareCreateOptions): Promise<{ shareClient: ShareClient, shareCreateResponse: ShareCreateResponse }>

參數

shareName

string

傳回

Promise<{ shareClient: ShareClient, shareCreateResponse: ShareCreateResponse }>

共用建立回應和對應的共享用戶端。

deleteShare(string, ShareDeleteMethodOptions)

刪除共用。

function deleteShare(shareName: string, options?: ShareDeleteMethodOptions): Promise<ShareDeleteResponse>

參數

shareName

string

傳回

共用刪除回應和對應的共享用戶端。

fromConnectionString(string, ShareClientOptions)

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

static function fromConnectionString(connectionString: string, options?: ShareClientOptions): ShareServiceClient

參數

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
ShareClientOptions

設定 HTTP 管線的選項。

傳回

來自指定連接字串的新 ShareServiceClient。

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

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

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

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

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

參數

expiresOn

Date

自選。 共用存取簽章失效的時間。 如果未指定,則預設為一小時后。

permissions
AccountSASPermissions

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

resourceTypes

string

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

options
ServiceGenerateAccountSasUrlOptions

選擇性參數。

傳回

string

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

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

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

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

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

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

參數

expiresOn

Date

自選。 共用存取簽章失效的時間。 如果未指定,則預設為一小時后。

permissions
AccountSASPermissions

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

resourceTypes

string

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

options
ServiceGenerateAccountSasUrlOptions

選擇性參數。

傳回

string

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

getProperties(ServiceGetPropertiesOptions)

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

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

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

參數

options
ServiceGetPropertiesOptions

取得屬性作業的選項。

傳回

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

getShareClient(string)

建立 ShareClient 物件。

function getShareClient(shareName: string): ShareClient

參數

shareName

string

共用的名稱。

傳回

指定共享名稱的 ShareClient 物件。

範例用法:

const shareClient = serviceClient.getShareClient("<share name>");
await shareClient.create();
console.log("Created share successfully!");

listShares(ServiceListSharesOptions)

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

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

使用 for await 語法的範例:

let i = 1;
for await (const share of serviceClient.listShares()) {
  console.log(`Share ${i++}: ${share.name}`);
}

使用 iter.next()的範例:

let i = 1;
let iter = serviceClient.listShares();
let shareItem = await iter.next();
while (!shareItem.done) {
  console.log(`Share ${i++}: ${shareItem.value.name}`);
  shareItem = await iter.next();
}

使用 byPage()的範例:

// passing optional maxPageSize in the page settings
let i = 1;
for await (const response of serviceClient.listShares().byPage({ maxPageSize: 20 })) {
  if (response.shareItems) {
   for (const share of response.shareItems) {
       console.log(`Share ${i++}: ${share.name}`);
    }
  }
}

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

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

// Prints 2 share names
if (response.shareItems) {
  for (const share of response.shareItems) {
    console.log(`Share ${i++}: ${share.name}`);
  }
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = serviceClient.listShares().byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

// Prints 10 share names
if (response.shareItems) {
  for (const share of response.shareItems) {
    console.log(`Share ${i++}: ${share.name}`);
  }
}
function listShares(options?: ServiceListSharesOptions): PagedAsyncIterableIterator<ShareItem, ServiceListSharesSegmentResponse, PageSettings>

參數

options
ServiceListSharesOptions

列出共用作業的選項。

支援分頁的 asyncIterableIterator。

傳回

setProperties(FileServiceProperties, ServiceSetPropertiesOptions)

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

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

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

參數

options
ServiceSetPropertiesOptions

設定屬性作業的選項。

傳回

設定屬性作業的響應數據。

undeleteShare(string, string, ServiceUndeleteShareOptions)

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

function undeleteShare(deletedShareName: string, deletedShareVersion: string, options?: ServiceUndeleteShareOptions): Promise<ShareClient>

參數

deletedShareName

string

先前刪除的共享名稱。

deletedShareVersion

string

先前已刪除共用的版本。

options
ServiceUndeleteShareOptions

共用取消刪除作業的選項。

傳回

Promise<ShareClient>

還原的共用。