次の方法で共有


Container.UpsertItemStreamAsync メソッド

定義

Azure Cosmos サービスの非同期操作としてアイテム ストリームをアップサートします。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage> UpsertItemStreamAsync (System.IO.Stream streamPayload, Microsoft.Azure.Cosmos.PartitionKey partitionKey, Microsoft.Azure.Cosmos.ItemRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertItemStreamAsync : System.IO.Stream * Microsoft.Azure.Cosmos.PartitionKey * Microsoft.Azure.Cosmos.ItemRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage>
Public MustOverride Function UpsertItemStreamAsync (streamPayload As Stream, partitionKey As PartitionKey, Optional requestOptions As ItemRequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResponseMessage)

パラメーター

streamPayload
Stream

Streamペイロードを含む 。

partitionKey
PartitionKey

項目のパーティション キー。

requestOptions
ItemRequestOptions

(省略可能)アイテム要求のオプション。

cancellationToken
CancellationToken

(省略可能) CancellationToken 要求の取り消しを表します。

戻り値

Task読み取りリソース レコードをResponseMessage含む をStreamラップする を含む 。

アイテムを含む Stream を Cosmos にアップサートする

using(ResponseMessage response = await this.container.UpsertItemStreamAsync(stream, new PartitionKey("itemPartitionKey")))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }

    //Read or do other operations with the stream
    using (StreamReader streamReader = new StreamReader(response.Content))
    {
        string content = await streamReader.ReadToEndAsync();
    }
}

注釈

Stream 操作では、クライアント側の例外のみがスローされます。 これは、パフォーマンスを向上させ、例外をスローするオーバーヘッドを防ぐためです。 操作が失敗した場合は、応答の HTTP 状態コードを確認してチェックします。

適用対象