Menu

Save large files in the browser without loading them into .NET
📰

Save large files in the browser without loading them into .NET

DEV Community: blazor·Todd Tanner·5 days ago
#7iIbQq20
#devtoblazor#devto#dev#app#using
Long article (2009 words) — no AI summary yet.
Reading 0:00
15s threshold

Live demo | Full example on GitHub

Your Blazor app lets people save a file for offline use. It works with a 2 MB photo. Then someone picks a 200 MB video, and your app has to find 200 MB of .NET memory to hold it.

Most of the time the app does not need those bytes in .NET at all. It only wants them moved from one place to another. The browser can do that itself.

This article saves the same file two ways and compares the .NET memory each one takes. You need the .NET 10 SDK and a browser.

Where the file goes

The origin private file system (OPFS) is file storage that belongs to your site. It needs no permission prompt, and other sites cannot read it. It does not show up as a normal folder on the user's disk.

Set up

dotnet new blazorwasm -o LargeFiles --empty cd LargeFiles dotnet add package SpawnDev.SpawnJS dotnet add package SpawnDev.SpawnJS.Blazor

Enter fullscreen mode

Exit fullscreen mode

Replace Program.cs :

using LargeFiles ; using Microsoft . AspNetCore . Components . WebAssembly .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.