@messageText" /> @messageText" /> @messageText"/>

Blazor InputFile seems to break for more than 243 Files

655 Views Asked by At

I am trying to use a Blazor InputFile to upload photos in a Blazor-Server-Project, using the code below

<h5 class="mb-1 text-danger">@messageText</h5>
<InputFile OnChange="@LoadFiles" class="form-control" multiple accept=".png,.jpg,.jpeg" />
@foreach (var image in images)
        {
            <div class="list-group-item list-group-item-action">
                <p>@image.Name</p>
            </div>
        }

@code {
    private string messageText = "";
    List<IBrowserFile?> images = new List<IBrowserFile?>();

    private async Task LoadFiles(InputFileChangeEventArgs e)
    {
        if (images.Count + e.FileCount > Constants.MaxImageCount)
        {
            messageText = "image overflow";
            
        }else{
            var files = e.GetMultipleFiles(Constants.MaxImageCount); //limit has to be defined there too
            foreach (var img in files.Where(x => x != null && x.ContentType.Contains("image")))
            {
                //change image type to jpg and reduce file size
                images.Add(img);
            }
        }
    }
}

For up to 243 images this works perfectly fine, the images get uploaded and rejected depending on the maxImageCount.

The Problem: As soon as i insert 244 or more images into the InputFile, the Blazor-Page just reloads and does nothing. I would expect it to just reject the files but LoadFiles(InputFileChangeEventArgs e) is never called.

Any help would be apprechiated!

1

There are 1 best solutions below

0
HerzogVolpe On

I found out!

I am hitting the SignalR-Limit for communication between Client and Server

https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-7.0#circuit-handler-options-for-blazor-server-apps

Hope i can prevent someone from having my headache :)