IBrowserFile.OpenReadStream(Int64, CancellationToken) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Opens the stream for reading the uploaded file.
public System.IO.Stream OpenReadStream (long maxAllowedSize = 512000, System.Threading.CancellationToken cancellationToken = default);
abstract member OpenReadStream : int64 * System.Threading.CancellationToken -> System.IO.Stream
Public Function OpenReadStream (Optional maxAllowedSize As Long = 512000, Optional cancellationToken As CancellationToken = Nothing) As Stream
Parameters
- maxAllowedSize
- Int64
The maximum number of bytes that can be supplied by the Stream. Defaults to 500 KB.
Calling OpenReadStream(Int64, CancellationToken)
will throw if the file's size, as specified by Size is larger than
maxAllowedSize
. By default, if the user supplies a file larger than 500 KB, this method will throw an exception.
It is valuable to choose a size limit that corresponds to your use case. If you allow excessively large files, this may result in excessive consumption of memory or disk/database space, depending on what your code does with the supplied Stream.
For Blazor Server in particular, beware of reading the entire stream into a memory buffer unless you have passed a suitably low size limit, since you will be consuming that memory on the server.
- cancellationToken
- CancellationToken
A cancellation token to signal the cancellation of streaming file data.
Returns
Exceptions
Thrown if the file's length exceeds the maxAllowedSize
value.