MultipartContent.CreateContentReadStreamAsync Method

Definition

Overloads

CreateContentReadStreamAsync()

Serializes the HTTP content to a stream using the multipart/* encoding as an asynchronous operation.

CreateContentReadStreamAsync(CancellationToken)

Serializes the HTTP content to a stream using the multipart/* encoding as an asynchronous operation.

CreateContentReadStreamAsync()

Source:
MultipartContent.cs
Source:
MultipartContent.cs
Source:
MultipartContent.cs

Serializes the HTTP content to a stream using the multipart/* encoding as an asynchronous operation.

C#
protected override System.Threading.Tasks.Task<System.IO.Stream> CreateContentReadStreamAsync();

Returns

The task object representing the asynchronous operation.

Remarks

This method overrides HttpContent.CreateContentReadStreamAsync to use a custom stream that contains an array, with each HTTP content and its boundary encoded and serialized to a MemoryStream instance.

This operation will not block. The returned Task<TResult> object will complete after all of the content has been written to the memory stream.

Once the operation completes, the Task<TResult>.Result property on the returned task object contains the stream that represents the multipart/* encoded HTTP content. The returned stream can then be used to read the content using various stream APIs.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

CreateContentReadStreamAsync(CancellationToken)

Source:
MultipartContent.cs
Source:
MultipartContent.cs
Source:
MultipartContent.cs

Serializes the HTTP content to a stream using the multipart/* encoding as an asynchronous operation.

C#
protected override System.Threading.Tasks.Task<System.IO.Stream> CreateContentReadStreamAsync(System.Threading.CancellationToken cancellationToken);

Parameters

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

The task object representing the asynchronous operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method overrides HttpContent.CreateContentReadStreamAsync to use a custom stream that contains an array, with each HTTP content and its boundary encoded and serialized to a MemoryStream instance.

This operation will not block. The returned Task<TResult> object will complete after all of the content has been written to the memory stream.

Once the operation completes, the Task<TResult>.Result property on the returned task object contains the stream that represents the multipart/* encoded HTTP content. The returned stream can then be used to read the content using various stream APIs.

Applies to

.NET 10 and other versions
Product Versions
.NET 5, 6, 7, 8, 9, 10