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

DocumentClient.ReadAttachmentAsync 方法

定义

重载

ReadAttachmentAsync(String, RequestOptions, CancellationToken)

Attachment以异步操作的形式从 Azure Cosmos DB 服务读取 。

ReadAttachmentAsync(Uri, RequestOptions, CancellationToken)

Attachment从 Azure Cosmos DB 服务以异步操作的形式读取 。

ReadAttachmentAsync(String, RequestOptions, CancellationToken)

Attachment以异步操作的形式从 Azure Cosmos DB 服务读取 。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> ReadAttachmentAsync (string attachmentLink, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadAttachmentAsync : string * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.ReadAttachmentAsync : string * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReadAttachmentAsync (attachmentLink As String, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

attachmentLink
String

指向要读取的附件的链接。

options
RequestOptions

(可选) 请求的请求选项。

cancellationToken
CancellationToken

(可选) A CancellationToken ,其他对象或线程可以使用它来接收取消通知。

返回

包含 System.Threading.Tasks 的 , ResourceResponse<TResource> 它包装 Attachment 包含读取资源记录的 。

实现

例外

如果未 attachmentLink 设置 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建文档时可能会获取的一些常见代码包括:

StatusCode异常原因
404NotFound - 这意味着尝试读取的资源不存在。
429TooManyRequests - 这意味着已超出每秒请求单位数。 请参阅 DocumentClientException.RetryAfter 值,了解在重试此操作之前应等待多长时间。

示例

//Reads an Attachment resource where
// - sample_db is the ID property of the Database
// - sample_coll is the ID property of the DocumentCollection
// - sample_doc is the ID property of the Document
// - attachment_id is the ID property of the Attachment resource you wish to read.
var attachLink = "/dbs/sample_db/colls/sample_coll/docs/sample_doc/attachments/attachment_id/";
Attachment attachment = await client.ReadAttachmentAsync(attachLink);

注解

读取资源是从服务获取资源的最有效方法。 如果知道资源的 ID,请执行读取,而不是按 ID 进行查询。

显示的示例使用基于 ID 的链接,其中链接由创建资源时使用的 ID 属性组成。 如果愿意, SelfLink 仍然可以使用 Database 的 属性。 自链接是由资源标识符 (或_rid属性) 组成的资源的 URI。 基于 ID 的链接和 SelfLink 都将正常工作。 的格式 attachmentLink 始终为“/dbs/{db identifier}/colls/{coll identifier}/docs/{doc identifier}/attachments/{attachment identifier}”,仅更改中的 {} 值,具体取决于要用于寻址资源的方法。

另请参阅

适用于

ReadAttachmentAsync(Uri, RequestOptions, CancellationToken)

Attachment从 Azure Cosmos DB 服务以异步操作的形式读取 。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> ReadAttachmentAsync (Uri attachmentUri, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadAttachmentAsync : Uri * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.ReadAttachmentAsync : Uri * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReadAttachmentAsync (attachmentUri As Uri, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

attachmentUri
Uri

要读取的附件资源的 URI。

options
RequestOptions

请求的请求选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

一个 System.Threading.TasksResourceResponse<TResource> ,它包含包装 Attachment 包含读取资源记录的 。

实现

例外

如果未 attachmentUri 设置 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建文档时可能会获取的一些常见代码包括:

StatusCode异常原因
404NotFound - 这意味着尝试读取的资源不存在。
429TooManyRequests - 这意味着已超出每秒请求单位数。 请参阅 DocumentClientException.RetryAfter 值,了解在重试此操作之前应等待多长时间。

示例

//Reads an Attachment resource where 
// - db_id is the ID property of the Database
// - coll_id is the ID property of the DocumentCollection
// - doc_id is the ID property of the Document
// - attachment_id is the ID property of the Attachment resource you wish to read. 
var attachLink = UriFactory.CreateAttachmentUri("db_id", "coll_id", "doc_id", "attachment_id");
Attachment attachment = await client.ReadAttachmentAsync(attachLink);

注解

读取资源是从服务获取资源的最有效方法。 如果知道资源的 ID,请执行读取,而不是按 ID 进行查询。

另请参阅

适用于