Container.CreateItemStreamAsync Methode

Definition

Erstellt ein Element als asynchronen Vorgang im Azure Cosmos-Dienst.

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)

Parameter

streamPayload
Stream

Ein Stream , der die Nutzlast enthält.

partitionKey
PartitionKey

Der Partitionsschlüssel für das Element.

requestOptions
ItemRequestOptions

(Optional) Die Optionen für die Elementanforderung.

cancellationToken
CancellationToken

(Optional) CancellationToken stellt den Anforderungsabbruch dar.

Gibt zurück

Die ResponseMessage erstellte , die in einem Task -Objekt enthalten ist, das die Dienstantwort für den asynchronen Vorgang darstellt.

Beispiele

In diesem Beispiel wird ein Element in einem Cosmos-Container erstellt.

//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();
    }
}

Hinweise

Der Stream-Vorgang löst nur clientseitige Ausnahmen aus. Dadurch soll die Leistung gesteigert und der Mehraufwand beim Auslösen von Ausnahmen vermieden werden. Überprüfen Sie den HTTP-status Code in der Antwort, um zu überprüfen, ob der Vorgang fehlgeschlagen ist.

Gilt für: