ShareServiceClient class
ShareServiceClient 代表 Azure 記憶體檔案服務的 URL,可讓您操作檔案共用。
- Extends
-
StorageClient
建構函式
Share |
建立 ShareServiceClient 的實例。 |
Share |
建立 ShareServiceClient 的實例。 |
繼承的屬性
account |
|
url | URL 字串值。 |
方法
create |
建立共用。 |
delete |
刪除共用。 |
from |
從連接字串建立 ShareServiceClient 的實例。 |
generate |
僅適用於以共用密鑰認證建構的 ShareServiceClient。 根據傳入的用戶端屬性和參數,產生帳戶共用存取簽章 (SAS) URI。 SAS 是由客戶端的共用金鑰認證所簽署。 請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas |
get |
取得記憶體帳戶檔案服務的屬性,包括記憶體分析和 CORS (跨原始來源資源分享) 規則的屬性。 請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties |
get |
建立 ShareClient 物件。 |
list |
傳回異步反覆運算器,以列出指定帳戶下的所有共用。 .byPage () 會傳回異步反覆運算器,以列出頁面中的共用。 使用語法的
使用
使用
搭配標記使用分頁的範例:
|
set |
設定記憶體帳戶檔案服務端點的屬性,包括記憶體分析、CORS (跨原始來源資源分享) 規則和虛刪除設定的屬性。 請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties |
undelete |
還原先前刪除的共用。 只有在針對與共用相關聯的記憶體帳戶啟用共用虛刪除時,此 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
例如 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
- options
- ShareCreateOptions
傳回
Promise<{ shareClient: ShareClient, shareCreateResponse: ShareCreateResponse }>
共用建立回應和對應的共享用戶端。
deleteShare(string, ShareDeleteMethodOptions)
刪除共用。
function deleteShare(shareName: string, options?: ShareDeleteMethodOptions): Promise<ShareDeleteResponse>
參數
- shareName
-
string
- options
- ShareDeleteMethodOptions
傳回
Promise<ShareDeleteResponse>
共用刪除回應和對應的共享用戶端。
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://docs.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
指定與共用存取簽章相關聯的資源類型。
選用參數。
傳回
string
帳戶 SAS URI,其中包含此用戶端所代表資源的 URI,後面接著產生的 SAS 令牌。
getProperties(ServiceGetPropertiesOptions)
取得記憶體帳戶檔案服務的屬性,包括記憶體分析和 CORS (跨原始來源資源分享) 規則的屬性。
請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties
function getProperties(options?: ServiceGetPropertiesOptions): Promise<ServiceGetPropertiesResponse>
參數
- options
- ServiceGetPropertiesOptions
取得屬性作業的選項。
傳回
Promise<ServiceGetPropertiesResponse>
取得屬性作業的響應數據。
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>
參數
傳回
setProperties(FileServiceProperties, ServiceSetPropertiesOptions)
設定記憶體帳戶檔案服務端點的屬性,包括記憶體分析、CORS (跨原始來源資源分享) 規則和虛刪除設定的屬性。
請參閱 https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties
function setProperties(properties: FileServiceProperties, options?: ServiceSetPropertiesOptions): Promise<ServiceSetPropertiesResponse>
參數
- properties
- FileServiceProperties
- options
- ServiceSetPropertiesOptions
設定屬性作業的選項。
傳回
Promise<ServiceSetPropertiesResponse>
設定屬性作業的響應數據。
undeleteShare(string, string, ServiceUndeleteShareOptions)
還原先前刪除的共用。 只有在針對與共用相關聯的記憶體帳戶啟用共用虛刪除時,此 API 才會運作。
function undeleteShare(deletedShareName: string, deletedShareVersion: string, options?: ServiceUndeleteShareOptions): Promise<ShareClient>
參數
- deletedShareName
-
string
先前刪除的共享名稱。
- deletedShareVersion
-
string
先前刪除的共用版本。
- options
- ServiceUndeleteShareOptions
共用取消刪除作業的選項。
傳回
Promise<ShareClient>
還原的共用。