Share via


IDocumentClient.UpdateMediaAsync Method

Definition

Replaces the specified media's content as an asynchronous operation in the Azure Cosmos DB service.

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

Parameters

mediaLink
String

The link for the media to be updated. /media/media_rid

mediaStream
Stream

The Stream of the attachment media.

options
MediaOptions

The MediaOptions 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.

Exceptions

If either mediaLink or mediaStream is not set.

If mediaLink is not in the form of /media/{mediaId}.

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))
{
    //Update the attachment media
    await client.UpdateMediaAsync("/media/media_rid", fileStream, 
                    new MediaOptions 
                    { 
                        ContentType = "application/pdf", 
                        Slug = "something.pdf" 
                    });
}

Applies to

See also