Share via


Container.CreateItemStreamAsync メソッド

定義

Azure Cosmos サービスで非同期操作として Item を作成します。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage> CreateItemStreamAsync (System.IO.Stream streamPayload, Microsoft.Azure.Cosmos.PartitionKey partitionKey, Microsoft.Azure.Cosmos.ItemRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateItemStreamAsync : 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 CreateItemStreamAsync (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 要求の取り消しを表します。

戻り値

非同期操作の ResponseMessage サービス応答を Task 表す オブジェクト内に格納されている 作成された 。

次の使用例は、Cosmos コンテナーに項目を作成します。

//Create the object in Cosmos
using (ResponseMessage response = await this.Container.CreateItemStreamAsync(partitionKey: new PartitionKey("streamPartitionKey"), streamPayload: stream))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }

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

注釈

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

適用対象