StreamPartialContent Class

Namespace: System.Net.Http
Assembly: System.Net.Http.dll

Represents a content type that is uploaded as a stream and can be partially sent. This class is useful for scenarios where you need to send large amounts of data without loading the entire content into memory.

public sealed class StreamPartialContent : HttpContent

Syntax

Declaration
public sealed class StreamPartialContent : HttpContent

Constructors

Properties

Methods

Remarks

The StreamPartialContent class is particularly useful when dealing with data sources that cannot be fully loaded into memory, such as large files or network streams. It allows for efficient transmission of data by reading and writing in chunks.

When creating an instance, you provide a Stream object. The maxBufferSize parameter controls how much data is read from the stream at a time, which can be important for performance tuning.

The Headers property allows you to set standard HTTP headers like 'Content-Type' and 'Content-Disposition'.

The SerializeToStreamAsync method is the core method responsible for writing the stream's content to the destination stream. The ComputeContentLengthAsync method might return -1 if the content length cannot be determined beforehand, which is common for streaming content.