diff --git a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs index 3cb3e6c748..a1d4846fb8 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs @@ -106,7 +106,9 @@ public override async Task SendAsync( && response.Content != null && response.Content is not CloneableStream) { - response.Content = await StreamExtension.AsClonableStreamAsync(response.Content, default); + response.Content = await StreamExtension.AsClonableStreamAsync( + mediaStream: response.Content, + allowUnsafeDataAccess: true); } return response; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs index ca7565cd2f..6e23513ff6 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs @@ -924,9 +924,14 @@ private async Task ProcessItemStreamAsync( string resourceUri = this.GetResourceUri(requestOptions, operationType, itemId); // Convert Text to Binary Stream. - streamPayload = CosmosSerializationUtil.TrySerializeStreamToTargetFormat( - targetSerializationFormat: ContainerCore.GetTargetRequestSerializationFormat(), - inputStream: streamPayload == null ? null : await StreamExtension.AsClonableStreamAsync(streamPayload)); + if (ConfigurationManager.IsBinaryEncodingEnabled()) + { + streamPayload = CosmosSerializationUtil.TrySerializeStreamToTargetFormat( + targetSerializationFormat: ContainerCore.GetTargetRequestSerializationFormat(), + inputStream: streamPayload == null ? null : await StreamExtension.AsClonableStreamAsync( + mediaStream: streamPayload, + allowUnsafeDataAccess: true)); + } ResponseMessage responseMessage = await this.ClientContext.ProcessResourceOperationStreamAsync( resourceUri: resourceUri,