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

IDocumentClient.UpsertAttachmentAsync 方法

定义

重载

UpsertAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作插入。

UpsertAttachmentAsync(Uri, Stream, MediaOptions, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作更新插入。

UpsertAttachmentAsync(String, Object, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作插入。

UpsertAttachmentAsync(String, Stream, MediaOptions, RequestOptions, CancellationToken)

使用 Azure Cosmos Attachment DB 服务中作为异步操作提供的 mediaStream 的内容插入 。

UpsertAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作插入。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> UpsertAttachmentAsync (Uri documentUri, object attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAttachmentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function UpsertAttachmentAsync (documentUri As Uri, attachment As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

documentUri
Uri

要为其更新插入附件的文档的 URI。

attachment
Object

Attachment 对象。

options
RequestOptions

(可选的) RequestOptions 请求的 。

cancellationToken
CancellationToken

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

返回

表示异步操作的服务响应的任务对象。

适用于

UpsertAttachmentAsync(Uri, Stream, MediaOptions, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作更新插入。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> UpsertAttachmentAsync (Uri documentUri, System.IO.Stream mediaStream, Microsoft.Azure.Documents.Client.MediaOptions options = default, Microsoft.Azure.Documents.Client.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAttachmentAsync : Uri * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function UpsertAttachmentAsync (documentUri As Uri, mediaStream As Stream, Optional options As MediaOptions = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

documentUri
Uri

要为其更新插入附件的文档的 URI。

mediaStream
Stream

附件媒体的流。

options
MediaOptions

该请求的 MediaOptions

requestOptions
RequestOptions

该请求的 RequestOptions

cancellationToken
CancellationToken

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

返回

表示异步操作的服务响应的任务对象。

适用于

UpsertAttachmentAsync(String, Object, RequestOptions, CancellationToken)

在 Azure Cosmos DB 服务中将附件作为异步操作插入。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> UpsertAttachmentAsync (string documentLink, object attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAttachmentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function UpsertAttachmentAsync (documentLink As String, attachment As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

documentLink
String

此新附件的父文档的链接。 例如 dbs/db_rid/colls/col_rid/docs/doc_rid/

attachment
Object

附件对象。

options
RequestOptions

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

cancellationToken
CancellationToken

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

返回

表示 Task 异步操作的服务响应的 对象。

示例

下面的示例创建一个新文档,然后为该文档重新插入一个新附件

dynamic d = new
{
    id = "DOC1800243243470"
};

Document doc = await client.CreateDocumentAsync(collectionSelfLink, d);

//Upsert an Attachment which links to binary content stored somewhere else
//Use the MediaLink property of Attachment to set where the binary resides
//MediaLink can also point at another Attachment within Azure Cosmos DB.
Attachment a = await client.UpsertAttachmentAsync(doc.SelfLink, new Attachment { Id = "foo", ContentType = "text/plain", MediaLink = "link to your media" });

另请参阅

适用于

UpsertAttachmentAsync(String, Stream, MediaOptions, RequestOptions, CancellationToken)

使用 Azure Cosmos Attachment DB 服务中作为异步操作提供的 mediaStream 的内容插入 。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> UpsertAttachmentAsync (string attachmentsLink, System.IO.Stream mediaStream, Microsoft.Azure.Documents.Client.MediaOptions options = default, Microsoft.Azure.Documents.Client.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAttachmentAsync : string * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function UpsertAttachmentAsync (attachmentsLink As String, mediaStream As Stream, Optional options As MediaOptions = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

attachmentsLink
String

文档的附件链接。 例如 dbs/db_rid/colls/col_rid/docs/doc_rid/attachments/

mediaStream
Stream

Stream附件媒体的 。

options
MediaOptions

MediaOptions请求的 。

requestOptions
RequestOptions

RequestOptions请求的 。

cancellationToken
CancellationToken

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

返回

表示异步操作的服务响应的任务对象。

例外

attachmentsLink如果未设置 或 mediaStream

示例

//This attachment could be any binary you want to attach. Like images, videos, word documents, pdfs etc. it doesn't matter
using (FileStream fileStream = new FileStream(@".\something.pdf", FileMode.Open))
{
    //Upsert the attachment
    Attachment attachment = await client.UpsertAttachmentAsync("dbs/db_rid/colls/coll_rid/docs/doc_rid/attachments/",
                                        fileStream,
                                        new MediaOptions
                                        {
                                            ContentType = "application/pdf",
                                            Slug = "something.pdf"
                                        });
}

另请参阅

适用于