DocumentClient.ReplaceAttachmentAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ReplaceAttachmentAsync(Attachment, RequestOptions, CancellationToken) |
Replaces a Attachment in the Azure Cosmos DB service as an asynchronous operation. |
ReplaceAttachmentAsync(Uri, Attachment, RequestOptions, CancellationToken) |
Replaces an attachment as an asynchronous operation in the Azure Cosmos DB service. |
ReplaceAttachmentAsync(Attachment, RequestOptions, CancellationToken)
Replaces a Attachment in the Azure Cosmos DB service as an asynchronous operation.
public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> ReplaceAttachmentAsync (Microsoft.Azure.Documents.Attachment attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAttachmentAsync : Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.ReplaceAttachmentAsync : Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReplaceAttachmentAsync (attachment As Attachment, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))
Parameters
- attachment
- Attachment
The updated Attachment to replace the existing resource with.
- 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
A System.Threading.Tasks containing a ResourceResponse<TResource> which wraps a Attachment containing the updated resource record.
Implements
Exceptions
If attachment
is not set.
This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:
StatusCode | Reason for exception |
---|---|
404 | NotFound - This means the resource you tried to delete did not exist. |
Examples
//Fetch the item to be updated
Attachment attachment = client.CreateAttachmentQuery(attachmentLink)
.Where(r => r.Id == "attachment id")
.AsEnumerable()
.SingleOrDefault();
//Update some properties on the found resource
attachment.MediaLink = "updated value";
//Now persist these changes to the database by replacing the original resource
Attachment updated = await client.ReplaceAttachmentAsync(attachment);
See also
Applies to
ReplaceAttachmentAsync(Uri, Attachment, RequestOptions, CancellationToken)
Replaces 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>> ReplaceAttachmentAsync (Uri attachmentUri, Microsoft.Azure.Documents.Attachment attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAttachmentAsync : Uri * Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.ReplaceAttachmentAsync : Uri * Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReplaceAttachmentAsync (attachmentUri As Uri, attachment As Attachment, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))
Parameters
- attachmentUri
- Uri
the URI of the attachment to be updated.
- attachment
- Attachment
the attachment resource.
- 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
Azure SDK for .NET