Skip to content

Commit 0bf44d6

Browse files
authored
Tweaks to file upload (#20321)
1 parent ab7f088 commit 0bf44d6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

aspnetcore/blazor/file-uploads.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to upload files in Blazor with the InputFile component.
55
monikerRange: '>= aspnetcore-5.0'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 09/29/2020
8+
ms.date: 10/27/2020
99
no-loc: ["ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
1010
uid: blazor/file-uploads
1111
---
@@ -28,8 +28,9 @@ By default, the user selects single files. Add the `multiple` attribute to permi
2828

2929
To read data from a user-selected file:
3030

31-
* Call `OpenReadStream` on the file and read from the returned stream. For more information, see the [File streams](#file-streams) section.
32-
* Use `ReadAsync`. By default, `ReadAsync` only allows reading a file smaller than 524,288 KB (512 KB) in size. This limit is present to prevent developers from accidentally reading large files in to memory. Specify a reasonable approximation for the maximum expected file size if larger files must be supported. Avoid reading the incoming file stream directly into memory. For example, don't copy file bytes into a <xref:System.IO.MemoryStream> or read as a byte array. These approaches can result in performance and security problems, especially in Blazor Server. Instead, consider copying file bytes to an external store, such as a a blob or a file on disk.
31+
* Call `Microsoft.AspNetCore.Components.Forms.IBrowserFile.OpenReadStream` on the file and read from the returned stream. For more information, see the [File streams](#file-streams) section.
32+
* The <xref:System.IO.Stream> returned by `OpenReadStream` enforces a maximum size in bytes of the `Stream` being read. By default, only files smaller than 524,288 KB (512 KB) in size are allowed to be read before any further reads would result in an exception. This limit is present to prevent developers from accidentally reading large files in to memory. The `maxAllowedSize` parameter on `Microsoft.AspNetCore.Components.Forms.IBrowserFile.OpenReadStream` can be used to specify a larger size if required.
33+
* Avoid reading the incoming file stream directly into memory. For example, don't copy file bytes into a <xref:System.IO.MemoryStream> or read as a byte array. These approaches can result in performance and security problems, especially in Blazor Server. Instead, consider copying file bytes to an external store, such as a a blob or a file on disk.
3334

3435
A component that receives an image file can call the `RequestImageFileAsync` convenience method on the file to resize the image data within the browser's JavaScript runtime before the image is streamed into the app.
3536

0 commit comments

Comments
 (0)