Table of Contents

Class ProgressStreamContent

Namespace
GenerativeAI.Core
Assembly
GenerativeAI.dll

A custom StreamContent implementation to track and report progress during upload.

public class ProgressStreamContent : HttpContent, IDisposable
Inheritance
ProgressStreamContent
Implements
Inherited Members
Extension Methods

Constructors

ProgressStreamContent(Stream, Action<double>)

Initializes a new instance of the ProgressStreamContent class.

public ProgressStreamContent(Stream stream, Action<double> progressCallback)

Parameters

stream Stream

The stream to upload with progress tracking.

progressCallback Action<double>

The callback to report upload progress as a percentage (0.0 to 100.0).

Methods

Dispose(bool)

Releases the unmanaged resources used by the ProgressStreamContent and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

SerializeToStreamAsync(Stream, TransportContext?)

Serializes the content of the stream to a target stream asynchronously while tracking and reporting the upload progress.

protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context)

Parameters

stream Stream

The stream where the content will be serialized.

context TransportContext

An optional transport context that provides additional information about the stream operation.

Returns

Task

A task representing the asynchronous operation of writing the content to the target stream.

TryComputeLength(out long)

Attempts to compute the length of the stream content.

protected override bool TryComputeLength(out long length)

Parameters

length long

When this method returns, contains the computed length of the stream if it exists; otherwise, 0.

Returns

bool

true if the length of the stream can be determined; otherwise, false.