Class UploadSource
The content of a file to upload in chunks (see UploadAsync<TResult>(InterpolatedApiPathHandler, UploadSource, ReadOnlySpan<(string Name, object? Value)>, object?, UploadOptions?, CancellationToken) and UploadStreamingAsync<TItem>(InterpolatedApiPathHandler, UploadSource, ReadOnlySpan<(string Name, object? Value)>, object?, UploadOptions?, CancellationToken)), with its name, length and content type. It reads any byte range of the content, so that each chunk is read from where it starts.
Namespace: Singulink.Net.Http.Api.Client
Assembly: Singulink.Net.Http.Api.Client.dll
Syntax
public abstract class UploadSource
Remarks
An upload reads one range at a time, in order, each into the buffer of a chunk, and sends a chunk whose request fails again from that buffer. It reads a range again only for a chunk that the service still lacks when the upload completes.
FromFile(string, string?, string?), FromStream(Stream, string, string?), FromStreamFactory(string, long, Func<CancellationToken, Task<Stream>>, string?) and Create(string, long, Func<long, Memory<byte>, CancellationToken, ValueTask<int>>, string?) create sources. A derived class implements ReadAsync(long, Memory<byte>, CancellationToken), and ReleaseAsync() if it keeps something open between reads.
Constructors
| Name | Description |
|---|---|
| UploadSource(string, long, string?) | Initializes a new instance of the UploadSource class with the specified file name, length and content type. |
Properties
| Name | Description |
|---|---|
| ContentType | Gets the content type of the file, such as |
| FileName | Gets the name of the file, which the service receives. |
| Length | Gets the length of the content in bytes. |
Methods
| Name | Description |
|---|---|
| Create(string, long, Func<long, Memory<byte>, CancellationToken, ValueTask<int>>, string?) | Creates a source whose reads call the specified function. |
| FromFile(string, string?, string?) | Creates a source that reads a file. Each read opens the file and checks that its length and last write time are still the ones it had when the source was created, so that a file that changes fails the read with an IOException instead of being uploaded with other content. Other processes can read, write and delete the file while a read has it open. |
| FromStream(Stream, string, string?) | Creates a source that reads a seekable stream by setting its position, one read at a time. The content is the whole stream, whose length is read now. A read of a stream whose length has changed since throws an IOException. The stream is not disposed. |
| FromStreamFactory(string, long, Func<CancellationToken, Task<Stream>>, string?) | Creates a source that reads streams that a function opens, one read at a time. It keeps a stream open between reads and reads it forward, setting
its position if it is seekable. It opens a new stream to go back in one that is not seekable, after a read fails, and after
ReleaseAsync(). A stream whose length differs from |
| ReadAsync(long, Memory<byte>, CancellationToken) | Reads bytes of the content, starting at the specified offset, into the buffer. |
| ReleaseAsync() | Releases what the source keeps open between reads, such as a stream. An upload calls it when it stops reading the source: once its chunks are sent, and when it fails or is cancelled. A later read opens what it needs again. An exception that it throws does not change how the upload goes on, and is traced as a warning (see Trace). Does nothing by default. |