From 013413196b96797b70ad496be3292556fc4ab92f Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 16 Feb 2023 09:45:53 -0500 Subject: [PATCH] File uploads file size limitations (#28306) --- aspnetcore/blazor/file-uploads.md | 46 +++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/aspnetcore/blazor/file-uploads.md b/aspnetcore/blazor/file-uploads.md index 1aea75c1f7..de3ab348d2 100644 --- a/aspnetcore/blazor/file-uploads.md +++ b/aspnetcore/blazor/file-uploads.md @@ -5,7 +5,7 @@ description: Learn how to upload files in Blazor with the InputFile component. monikerRange: '>= aspnetcore-5.0' ms.author: riande ms.custom: mvc -ms.date: 12/17/2022 +ms.date: 02/04/2023 uid: blazor/file-uploads zone_pivot_groups: blazor-hosting-models --- @@ -46,13 +46,6 @@ To read data from a user-selected file, call enforces a maximum size in bytes of its . Reading one file or multiple files larger than 500 KB results in an exception. This limit prevents developers from accidentally reading large files into memory. The `maxAllowedSize` parameter of can be used to specify a larger size if required. -:::moniker range="< aspnetcore-6.0" - -> [!NOTE] -> In ASP.NET Core 5.0, the maximum supported file size is 2 GB. In ASP.NET Core 6.0 or later, the framework doesn't limit the maximum file size. - -:::moniker-end - If you need access to a that represents the file's bytes, use . Avoid reading the incoming file stream directly into memory all at once. For example, don't copy all of the file's bytes into a or read the entire stream into a byte array all at once. These approaches can result in performance and security problems, especially for Blazor Server apps. Instead, consider adopting either of the following approaches: * On the server of a hosted Blazor WebAssembly app or a Blazor Server app, copy the stream directly to a file on disk without reading it into memory. Note that Blazor apps aren't able to access the client's file system directly. @@ -92,6 +85,43 @@ await blobContainerClient.UploadBlobAsync( A component that receives an image file can call the convenience method on the file to resize the image data within the browser's JavaScript runtime before the image is streamed into the app. Use cases for calling are most appropriate for Blazor WebAssembly apps. +## File size read and upload limits + +:::moniker range=">= aspnetcore-6.0" + +:::zone pivot="server" + +There's no file size read or upload limit for the component in Blazor Server apps. + +:::zone-end + +:::zone pivot="webassembly" + +Prior to the release of ASP.NET Core 6.0, the component had a file size read limit of 2 GB. In ASP.NET Core 6.0 or later, the component has no file size read limit. + +In all versions of ASP.NET Core to date, Blazor WebAssembly reads the file's bytes into a single JavaScript array buffer when marshalling the data from JavaScript to C#, which is limited to 2 GB or to the device's available memory. Large file uploads (> 250 MB) may fail. + + + +:::zone-end + +:::moniker-end + +:::moniker range="< aspnetcore-6.0" + +The maximum supported file size for the component is 2 GB. + +To resolve the file size read limitation, we recommend implementing file uploads entirely in JavaScript by [streaming requests with the Fetch API](https://developer.chrome.com/articles/fetch-streaming-requests/). + +:::moniker-end + +## Upload files example + The following example demonstrates multiple file upload in a component. allows reading multiple files. Specify the maximum number of files to prevent a malicious user from uploading a larger number of files than the app expects. allows reading the first and only file if the file upload doesn't support multiple files. > [!NOTE]