question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser crash on iOS for client site image resizing with large number of files- Blazor Web Assembly (RequestImageFileAsync)

See original GitHub issue

During testing desktop pcs with a large amount of memory work well. However on systems with a low amount of memory the browser will crash.

On my iPad Air (4th generation iOS version 14.5) I can resize about 400 pictures but after that point it will crash the browser. I setup a demo site to demonstrate the issue: https://blazorimageresize.azurewebsites.net

Here is a recording of the browser crash on the iOS device: https://drive.google.com/file/d/1WR7ykyR7Q0tYb0D5umrj2J6odTvRsPCa/view?usp=sharing

async Task OnInputFileChange(InputFileChangeEventArgs e)
        {
        var imageFiles = e.GetMultipleFiles(2000);

        var format = "image/jpg";
        foreach (var imageFile in imageFiles)
        {
            var resizedImageFile = await imageFile.RequestImageFileAsync(format, 1920, 1080);          
        }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Aug 9, 2021

Thanks @lewing, we’ll take a look.

0reactions
MichelJanssoncommented, Aug 10, 2021

Looks like this is a dupe of #35156

@mkArtakMSFT I have been studying InputFile quite a bit over the last few days, and while these are similar, #35156 is probably not the only reason for this crash.

#35156 is about the ObjectURL of the source file, and since that is a JS File object (from the File API) it should only hold a reference to the file in local file system (unless iOS is doing it differently…).

Though what I think is happening here is what @pavelsavara touched on, the result of the resize is stored as a blob on the input element to later be accessed via the IBlazorFile.OpenReadStream. This will probably quickly consume quite a bit of memory. Chromium docs also warns about creating large blobs too fast.

A solution to this issue could be to stream the resize results directly into .NET via a IJSStreamReference (6.0 preview 7) instead of a “faked” BrowserFile. This way it can be read directly, and when IJSStreamReference is disposed, it should also release the blob on the JS side. This of course requires a change of the public API…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control over format when using RequestImageFileAsync in ...
This method takes a format as a string which determines the format of the output file.
Read more >
Resize images before uploading in Blazor Web Assembly
In this article, I take a look at how to do that, and how to get the dimensions of an image file. When...
Read more >
1st try with Blazor, Chrome crashes on repeated login
Run the app, login as the user I created. It logs in successfully. Click logout. It logs out successfully. Click login again, the...
Read more >
Blazor: Resize and Upload Image Files
Example of resizing and uploading image files to a Web API or REST API ... It resizes images on the client-side, utilizing client...
Read more >
[Fix]-Resize Image (jpg) in Blazor WebAssembly?
NET 5 has an extension method to IBrowserFile called RequestImageFileAsync. Per the documentation, it "Attempts to convert the current image file to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found