Share via


DocumentClient.UpsertAttachmentAsync Method

Definition

Overloads

UpsertAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

Upserts an attachment as an asynchronous operation in the Azure Cosmos DB service.

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

Upserts an attachment as an asynchronous operation in the Azure Cosmos DB service.

UpsertAttachmentAsync(String, Object, RequestOptions, CancellationToken)

Upserts an attachment as an asychronous operation in the Azure Cosmos DB service.

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

Upserts an Attachment with the contents of the provided mediaStream as an asynchronous operation in the Azure Cosmos DB service.

UpsertAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

Upserts an attachment as an asynchronous operation in the Azure Cosmos DB service.

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>>
override this.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))

Parameters

documentUri
Uri

the URI of the document to upsert an attachment for.

attachment
Object

the attachment object.

options
RequestOptions

The request options for the request.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

The task object representing the service response for the asynchronous operation.

Implements

Applies to

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

Upserts an attachment as an asynchronous operation in the Azure Cosmos DB service.

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>>
override this.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))

Parameters

documentUri
Uri

the URI of the document to upsert an attachment for.

mediaStream
Stream

the stream of the attachment media.

options
MediaOptions

the media options for the request.

requestOptions
RequestOptions

Request options for the request.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

The task object representing the service response for the asynchronous operation.

Implements

Applies to

UpsertAttachmentAsync(String, Object, RequestOptions, CancellationToken)

Upserts an attachment as an asychronous operation in the Azure Cosmos DB service.

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>>
override this.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))

Parameters

documentLink
String

The link of the parent document for this new attachment. E.g. dbs/db_rid/colls/col_rid/docs/doc_rid/

attachment
Object

The attachment object.

options
RequestOptions

(Optional) The request options for the request.

cancellationToken
CancellationToken

(Optional) A CancellationToken that can be used by other objects or threads to receive notice of cancellation.

Returns

The Task object representing the service response for the asynchronous operation.

Implements

Examples

The example below creates a new document, and then upserts a new attachment for that document

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" });

See also

Applies to

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

Upserts an Attachment with the contents of the provided mediaStream as an asynchronous operation in the Azure Cosmos DB service.

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>>
override this.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))

Parameters

attachmentsLink
String

The attachments link for the document. E.g. dbs/db_rid/colls/col_rid/docs/doc_rid/attachments/

mediaStream
Stream

the Stream of the attachment media.

options
MediaOptions

the MediaOptions for the request.

requestOptions
RequestOptions

the RequestOptions for the request.

cancellationToken
CancellationToken

(Optional) A CancellationToken that can be used by other objects or threads to receive notice of cancellation.

Returns

The task object representing the service response for the asynchronous operation.

Implements

Exceptions

If either attachmentsLink or mediaStream is not set.

Examples

//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"
                                        });
}

See also

Applies to