Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Markdown ImageUploadChanged throws exception and has "odd" behavior #5961

Closed
linkdotnet opened this issue Feb 2, 2025 · 0 comments
Closed
Assignees
Labels
Type: Bug 🐞 Something isn't working
Milestone

Comments

@linkdotnet
Copy link

Blazorise Version

1.7.3

What Blazorise provider are you running on?

Bootstrap5

Link to minimal reproduction or a simple code snippet

<Markdown ImageUploadChanged="ImageUploadChanged"></Markdown>

@code {
    private async Task ImageUploadChanged(FileChangedEventArgs events)
    {
        try
        {
            var count = events.Files.Length; // Prints always one 

            foreach (var file in events.Files)
            {
                using var memoryStream = new MemoryStream();
                await file.WriteToStreamAsync(memoryStream);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }
}

Steps to reproduce & bug description

Using the Markdown component in combination with uploading multiple files/images at once leads to a NullReferenceException.

The "odd" thing here is that events.Files.Length will always be one, independent of how many items you drag and drop onto the markdown field. That said, for each file dropped, the ImageUploadChanged will be invoked.

In a given scenario where you drop at least two or more files, await file.WriteToStreamAsync(memoryStream); will throw with the given exception.

What is expected?

Aside from the exception, that shouldn't throw. I think it would be more obvious for folks if it either follows more closely what InputFileChangeEventArgs is doing (aka GetMultipleFiles) or populate the array with all the items, rather than invoking the callback once per file.

What is actually happening?

  1. NullReferenceException
  2. The FileChangedEventArgs.Files array only consists of one item

What browsers do you see the problem on?

No response

Any additional comments?

Here the stack trace of the second invocation:

   at Blazorise.RemoteFileEntryStreamReader.OpenReadStreamAsync(CancellationToken cancellationToken)
   at Blazorise.RemoteFileEntryStreamReader.CopyFileDataIntoBuffer(Memory`1 destination, CancellationToken cancellationToken)
   at Blazorise.RemoteFileEntryStreamReader.WriteToStreamAsync(Stream stream, CancellationToken cancellationToken)
   at Blazorise.RemoteFileEntryStreamReader.WriteToStreamAsync(Stream stream, CancellationToken cancellationToken)
   at Blazorise.FileEntry.WriteToStreamAsync(Stream stream, CancellationToken cancellationToken)
   at Bug.Components.Pages.Home.ImageUploadChanged(FileChangedEventArgs events) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐞 Something isn't working
Projects
Status: ✔ Done
Development

No branches or pull requests

3 participants