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

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://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas

getProperties(ServiceGetPropertiesOptions)

获取存储帐户的文件服务的属性,包括 存储分析 和 CORS (跨域资源共享) 规则的属性。

请参见https://docs.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://docs.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://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 令牌。

getProperties(ServiceGetPropertiesOptions)

获取存储帐户的文件服务的属性,包括 存储分析 和 CORS (跨域资源共享) 规则的属性。

请参见https://docs.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://docs.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>

还原的共享。