


❌ The following approach is NOT recommended because the file's Stream content is read into a String in memory ( reader): var reader =Īwait new StreamReader(browserFile.OpenReadStream()).ReadToEndAsync() In the following examples, browserFile represents the uploaded file and implements IBrowserFile: If you need access to a Stream that represents the file's bytes, use IBrowserFile.OpenReadStream.

Instead, consider copying file bytes to an external store, such as a blob or a file on disk. These approaches can result in performance and security problems, especially in Blazor Server. For example, don't copy file bytes into a MemoryStream or read as a byte array. The maxAllowedSize parameter of OpenReadStream can be used to specify a larger size if required.Īvoid reading the incoming file stream directly into memory. This limit prevents developers from accidentally reading large files in to memory. Reading one file or multiple files larger than 512,000 bytes (500 KB) results in an exception. OpenReadStream enforces a maximum size in bytes of its Stream. For more information, see the File streams section. To read data from a user-selected file, call IBrowserFile.OpenReadStream on the file and read from the returned stream. In the preceding example, the element's _bl_2 attribute is used for Blazor's internal processing.
