I have this in my razor.component file
<MudFileUpload T="IReadOnlyList<IBrowserFile>" FilesChanged="InsertFiles" Accept=".jpg, .png, .bmp" Style="display:contents"></MudFileUpload><MudButton Variant="Variant.Filled" EndIcon="@Icons.Material.Filled.Send" Color="Color.Primary" FullWidth="true" ButtonType="ButtonType.Submit" Class="btn-user ml-4" Disabled="@buttonDisabled"> Submit</MudButton>If I select multiple items all at the same time and "submit", I do not get any errors up to my API. But if I select 1 file at a time, then I get an error of
There is no file with ID 1. The file list may have changed.
during "submit".
Putting it into context, if I use a PC, I can just drag my mouse to files I need and just click on the "open" button. But if I am using a phone, I cannot select multiple items at the same time, I would need to select 1 file at a time and click the open button to add it to the list I need to upload. But as I have mentioned, If I click one file then open it, then, click on the file input button again and select another file, my list actually grows from 1 file to 2 files then 3 files and so on. But when I click on the "submit" button, that's the time I get an error. If I just select 1 file or mutiple files at once then "submit", I do not get any issues. Please see my component.razor.cs
private IList<IBrowserFile> files = new List<IBrowserFile>();private void InsertFiles(IReadOnlyList<IBrowserFile> files){ var fileSize = 0f; foreach (var item in files) { fileSize = totalFileSize + item.Size; this.files.Add(item); }}private async Task SubmitAsync(){ try { using var content = new MultipartFormDataContent(); foreach (var file in this.files) { var fileContent = new StreamContent(file.OpenReadStream(maxFileSize)); fileContent.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType); content.Add( content: fileContent, name: "\"files\"", fileName: file.Name); } var response = await mHttpService!.Post<List<UploadResult>>("api/some-end-point", content); } catch (Exception e) { Console.WriteLine(e.Message); mSnackbar!.Add($@"Exception ecountered: {e.Message}", Severity.Error); }}