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

ShareClient class

ShareClient 表示 Azure 存储共享的 URL,允许你操作其目录和文件。

Extends

StorageClient

构造函数

ShareClient(string, Credential_2 | TokenCredential, ShareClientOptions)

创建 ShareClient 的实例。

ShareClient(string, Pipeline, ShareClientConfig)

创建 ShareClient 的实例。

ShareClient(string, string, ShareClientOptions)

属性

name

共享的名称

rootDirectoryClient

获取此共享的根目录的目录客户端。 请注意,根目录始终存在,并且无法删除。

根目录的新 ShareDirectoryClient 对象。

继承属性

accountName
url

URL 字符串值。

方法

create(ShareCreateOptions)

在指定的帐户下创建新共享。 如果已存在同名的共享,操作将失败。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-share

createDirectory(string, DirectoryCreateOptions)

在此共享下创建新的子目录。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory

createFile(string, number, FileCreateOptions)

创建一个新文件或替换此共享的根目录下的文件。 请注意,它仅初始化不带内容的文件。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-file

createIfNotExists(ShareCreateOptions)

在指定的帐户下创建新共享。 如果同名的共享已存在,则不会更改。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-share

createPermission(string, ShareCreatePermissionOptions)

在共享级别 (安全描述符) 创建文件权限。 创建的安全描述符可用于共享中的文件/目录。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-permission

createSnapshot(ShareCreateSnapshotOptions)

创建共享的只读快照。

delete(ShareDeleteMethodOptions)

标记要删除的指定共享。 共享及其中包含的任何目录或文件稍后在垃圾回收期间被删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share

deleteDirectory(string, DirectoryDeleteOptions)

删除此共享下的指定空子目录。 请注意,目录必须是空的,然后才能将其删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-directory

deleteFile(string, FileDeleteOptions)

从存储帐户中删除此共享的根目录下的文件。 成功删除文件后,它将从存储帐户的索引中删除,客户端不再能访问。 该文件的数据将在稍后的垃圾回收期间从服务中删除。

如果文件在 SMB 客户端上打开,则删除文件将失败并显示状态代码 409 (冲突) 和错误代码 SharingViolation

共享快照(共享的只读副本)不支持删除文件。 尝试对共享快照执行此操作会失败,400 (InvalidQueryParameterValue)

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2

deleteIfExists(ShareDeleteMethodOptions)

标记要删除的指定共享(如果存在)。 共享及其中包含的任何目录或文件稍后在垃圾回收期间被删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share

exists(ShareExistsOptions)

如果此客户端表示的 Azrue 共享资源存在,则返回 true;否则为 false。

注意:请谨慎使用此函数,因为现有共享可能会被其他客户端或应用程序删除。 反之亦然,此函数完成后,其他客户端或应用程序可能会添加新共享。

generateSasUrl(ShareGenerateSasUrlOptions)

仅适用于使用共享密钥凭据构造的 ShareClient。

根据传入的客户端属性和参数, (SAS) URI 生成服务共享访问签名。 SAS 由客户端的共享密钥凭据签名。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas

getAccessPolicy(ShareGetAccessPolicyOptions)

获取指定共享的权限。 权限指示是否可以公开访问共享数据。

警告:分析开始和过期字符串时,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-share-acl

getDirectoryClient(string)

创建 ShareDirectoryClient 对象。

getPermission(string, ShareGetPermissionOptions)

获取给定文件权限密钥的安全描述符定义语言 (SDDL) ,该密钥指示安全描述符。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-permission

getProperties(ShareGetPropertiesOptions)

返回指定共享的所有用户定义的元数据和系统属性。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-properties

警告:响应 metadata 中返回的对象将具有小写的键,即使它们最初包含大写字符。 这不同于 ShareServiceClient 方法使用 includeMetadata 选项返回listShares的元数据键,后者将保留其原始大小写。

getStatistics(ShareGetStatisticsOptions)

检索与共享相关的统计信息。

setAccessPolicy(SignedIdentifier[], ShareSetAccessPolicyOptions)

设置指定共享的权限。 权限指示共享中的目录或文件是否可以公开访问。

为共享设置权限时,将替换现有权限。 如果未提供 shareAcl,则将删除现有的共享 ACL。

在共享上建立存储访问策略时,最长可能需要 30 秒才能生效。 在此期间,与该存储访问策略关联的共享访问签名将失败,状态代码为 403(禁止访问),直到访问策略成为活动的。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-acl

setMetadata(Metadata, ShareSetMetadataOptions)

为指定的共享设置一个或多个用户定义的名称-值对。

如果未提供任何选项,或者选项参数中未定义任何元数据,则将删除共享元数据。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-metadata

setProperties(ShareSetPropertiesOptions)

设置共享的属性。

setQuota(number, ShareSetQuotaOptions)

设置指定共享的配额。

withSnapshot(string)

创建与源相同的新 ShareClient 对象,但具有指定的快照时间戳。 提供“”将删除快照并将 URL 返回到基本共享。

构造函数详细信息

ShareClient(string, Credential_2 | TokenCredential, ShareClientOptions)

创建 ShareClient 的实例。

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

参数

url

string

指向 Azure 存储文件共享的 URL 字符串,例如“https://myaccount.file.core.windows.net/share"”。 如果使用 AnonymousCredential,则可以追加 SAS,例如“https://myaccount.file.core.windows.net/share?sasString"”。

credential

Credential | TokenCredential

例如 AnonymousCredential 或 StorageSharedKeyCredential。 如果未指定,则使用 AnonymousCredential。

options
ShareClientOptions

可选。 用于配置 HTTP 管道的选项。

ShareClient(string, Pipeline, ShareClientConfig)

创建 ShareClient 的实例。

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

参数

url

string

指向 Azure 存储文件共享的 URL 字符串,例如“https://myaccount.file.core.windows.net/share"”。 如果使用 AnonymousCredential,则可以追加 SAS,例如“https://myaccount.file.core.windows.net/share?sasString"”。

pipeline
Pipeline

调用 newPipeline () 以创建默认管道或提供自定义管道。

ShareClient(string, string, ShareClientOptions)

new ShareClient(connectionString: string, name: string, options?: ShareClientOptions)

参数

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

name

string

共享名称。

options
ShareClientOptions

可选。 用于配置 HTTP 管道的选项。

属性详细信息

name

共享的名称

string name

属性值

string

rootDirectoryClient

获取此共享的根目录的目录客户端。 请注意,根目录始终存在,并且无法删除。

根目录的新 ShareDirectoryClient 对象。

ShareDirectoryClient rootDirectoryClient

属性值

继承属性详细信息

accountName

accountName: string

属性值

string

继承自 StorageClient.accountName

url

URL 字符串值。

url: string

属性值

string

继承自 StorageClient.url

方法详细信息

create(ShareCreateOptions)

在指定的帐户下创建新共享。 如果已存在同名的共享,操作将失败。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-share

function create(options?: ShareCreateOptions): Promise<ShareCreateResponse>

参数

options
ShareCreateOptions

共享创建操作的选项。

返回

共享创建操作的响应数据。

createDirectory(string, DirectoryCreateOptions)

在此共享下创建新的子目录。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory

function createDirectory(directoryName: string, options?: DirectoryCreateOptions): Promise<{ directoryClient: ShareDirectoryClient, directoryCreateResponse: DirectoryCreateResponse }>

参数

directoryName

string

options
DirectoryCreateOptions

目录创建操作的选项。

返回

Promise<{ directoryClient: ShareDirectoryClient, directoryCreateResponse: DirectoryCreateResponse }>

目录创建响应数据和相应的目录客户端。

createFile(string, number, FileCreateOptions)

创建一个新文件或替换此共享的根目录下的文件。 请注意,它仅初始化不带内容的文件。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-file

function createFile(fileName: string, size: number, options?: FileCreateOptions): Promise<{ fileClient: ShareFileClient, fileCreateResponse: FileCreateResponse }>

参数

fileName

string

size

number

指定文件的最大大小(以字节为单位),最大为 4 TB。

options
FileCreateOptions

文件创建操作的选项。

返回

Promise<{ fileClient: ShareFileClient, fileCreateResponse: FileCreateResponse }>

文件创建响应数据和相应的文件客户端。

createIfNotExists(ShareCreateOptions)

在指定的帐户下创建新共享。 如果同名的共享已存在,则不会更改。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-share

function createIfNotExists(options?: ShareCreateOptions): Promise<ShareCreateIfNotExistsResponse>

参数

返回

createPermission(string, ShareCreatePermissionOptions)

在共享级别 (安全描述符) 创建文件权限。 创建的安全描述符可用于共享中的文件/目录。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/create-permission

function createPermission(filePermission: string, options?: ShareCreatePermissionOptions): Promise<ShareCreatePermissionResponse>

参数

filePermission

string

SDDL 中所述的文件权限

options
ShareCreatePermissionOptions

共享创建权限操作的选项。

返回

createSnapshot(ShareCreateSnapshotOptions)

创建共享的只读快照。

function createSnapshot(options?: ShareCreateSnapshotOptions): Promise<ShareCreateSnapshotResponse>

参数

options
ShareCreateSnapshotOptions

共享创建快照操作的选项。

返回

共享创建快照操作的响应数据。

delete(ShareDeleteMethodOptions)

标记要删除的指定共享。 共享及其中包含的任何目录或文件稍后在垃圾回收期间被删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share

function delete(options?: ShareDeleteMethodOptions): Promise<ShareDeleteResponse>

参数

options
ShareDeleteMethodOptions

共享删除操作的选项。

返回

共享删除操作的响应数据。

deleteDirectory(string, DirectoryDeleteOptions)

删除此共享下的指定空子目录。 请注意,目录必须是空的,然后才能将其删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-directory

function deleteDirectory(directoryName: string, options?: DirectoryDeleteOptions): Promise<DirectoryDeleteResponse>

参数

directoryName

string

options
DirectoryDeleteOptions

目录删除操作的选项。

返回

目录删除响应数据。

deleteFile(string, FileDeleteOptions)

从存储帐户中删除此共享的根目录下的文件。 成功删除文件后,它将从存储帐户的索引中删除,客户端不再能访问。 该文件的数据将在稍后的垃圾回收期间从服务中删除。

如果文件在 SMB 客户端上打开,则删除文件将失败并显示状态代码 409 (冲突) 和错误代码 SharingViolation

共享快照(共享的只读副本)不支持删除文件。 尝试对共享快照执行此操作会失败,400 (InvalidQueryParameterValue)

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2

function deleteFile(fileName: string, options?: FileDeleteOptions): Promise<FileDeleteResponse>

参数

fileName

string

options
FileDeleteOptions

文件删除操作的选项。

返回

承诺文件删除响应数据。

deleteIfExists(ShareDeleteMethodOptions)

标记要删除的指定共享(如果存在)。 共享及其中包含的任何目录或文件稍后在垃圾回收期间被删除。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share

function deleteIfExists(options?: ShareDeleteMethodOptions): Promise<ShareDeleteIfExistsResponse>

参数

返回

exists(ShareExistsOptions)

如果此客户端表示的 Azrue 共享资源存在,则返回 true;否则为 false。

注意:请谨慎使用此函数,因为现有共享可能会被其他客户端或应用程序删除。 反之亦然,此函数完成后,其他客户端或应用程序可能会添加新共享。

function exists(options?: ShareExistsOptions): Promise<boolean>

参数

options
ShareExistsOptions

“存在”操作的选项。

返回

Promise<boolean>

generateSasUrl(ShareGenerateSasUrlOptions)

仅适用于使用共享密钥凭据构造的 ShareClient。

根据传入的客户端属性和参数, (SAS) URI 生成服务共享访问签名。 SAS 由客户端的共享密钥凭据签名。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas

function generateSasUrl(options: ShareGenerateSasUrlOptions): string

参数

options
ShareGenerateSasUrlOptions

可选参数。

返回

string

SAS URI 由此客户端表示的资源的 URI 组成,后跟生成的 SAS 令牌。

getAccessPolicy(ShareGetAccessPolicyOptions)

获取指定共享的权限。 权限指示是否可以公开访问共享数据。

警告:分析开始和过期字符串时,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-share-acl

function getAccessPolicy(options?: ShareGetAccessPolicyOptions): Promise<ShareGetAccessPolicyResponse>

参数

返回

共享获取访问策略操作的响应数据。

getDirectoryClient(string)

创建 ShareDirectoryClient 对象。

function getDirectoryClient(directoryName: string): ShareDirectoryClient

参数

directoryName

string

目录名称

返回

给定目录名称的 ShareDirectoryClient 对象。

getPermission(string, ShareGetPermissionOptions)

获取给定文件权限密钥的安全描述符定义语言 (SDDL) ,该密钥指示安全描述符。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-permission

function getPermission(filePermissionKey: string, options?: ShareGetPermissionOptions): Promise<ShareGetPermissionResponse>

参数

filePermissionKey

string

指示权限的安全描述符的文件权限键。

options
ShareGetPermissionOptions

共享创建权限操作的选项。

返回

getProperties(ShareGetPropertiesOptions)

返回指定共享的所有用户定义的元数据和系统属性。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-properties

警告:响应 metadata 中返回的对象将具有小写的键,即使它们最初包含大写字符。 这不同于 ShareServiceClient 方法使用 includeMetadata 选项返回listShares的元数据键,后者将保留其原始大小写。

function getProperties(options?: ShareGetPropertiesOptions): Promise<ShareGetPropertiesResponse>

参数

返回

共享获取属性操作的响应数据。

getStatistics(ShareGetStatisticsOptions)

检索与共享相关的统计信息。

function getStatistics(options?: ShareGetStatisticsOptions): Promise<ShareGetStatisticsResponse>

参数

返回

共享获取统计信息操作的响应数据。

setAccessPolicy(SignedIdentifier[], ShareSetAccessPolicyOptions)

设置指定共享的权限。 权限指示共享中的目录或文件是否可以公开访问。

为共享设置权限时,将替换现有权限。 如果未提供 shareAcl,则将删除现有的共享 ACL。

在共享上建立存储访问策略时,最长可能需要 30 秒才能生效。 在此期间,与该存储访问策略关联的共享访问签名将失败,状态代码为 403(禁止访问),直到访问策略成为活动的。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-acl

function setAccessPolicy(shareAcl?: SignedIdentifier[], options?: ShareSetAccessPolicyOptions): Promise<ShareSetAccessPolicyResponse>

参数

shareAcl

SignedIdentifier[]

已签名标识符的数组,每个标识符都具有访问策略的唯一 ID 和详细信息。

返回

共享集访问策略操作的响应数据。

setMetadata(Metadata, ShareSetMetadataOptions)

为指定的共享设置一个或多个用户定义的名称-值对。

如果未提供任何选项,或者选项参数中未定义任何元数据,则将删除共享元数据。

请参见https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-metadata

function setMetadata(metadata?: Metadata, options?: ShareSetMetadataOptions): Promise<ShareSetMetadataResponse>

参数

metadata
Metadata

如果未提供元数据,则将删除所有现有目录元数据。

返回

共享集元数据操作的响应数据。

setProperties(ShareSetPropertiesOptions)

设置共享的属性。

function setProperties(options?: ShareSetPropertiesOptions): Promise<ShareSetPropertiesResponse>

参数

返回

共享集属性操作的响应数据。

setQuota(number, ShareSetQuotaOptions)

警告

现已弃用此 API。

Use setProperties instead.

设置指定共享的配额。

function setQuota(quotaInGB: number, options?: ShareSetQuotaOptions): Promise<ShareSetPropertiesResponse>

参数

quotaInGB

number

指定共享的最大大小(以 GB 为单位)

返回

共享获取配额操作的响应数据。

withSnapshot(string)

创建与源相同的新 ShareClient 对象,但具有指定的快照时间戳。 提供“”将删除快照并将 URL 返回到基本共享。

function withSnapshot(snapshot: string): ShareClient

参数

snapshot

string

快照时间戳。

返回

与源相同的新 ShareClient 对象,但具有指定的快照时间戳