Markdown: ImageUploadChanged with multiple files fix #5975
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #5961
This effectively fixes the issue. The previous implementation overwrote the
_blazorFilesById
dictionary, which resulted in this errorwhen calling
await file.WriteToStreamAsync(memoryStream);
The fix works, but there are plenty of areas for improvement.
Files One by One, Not Grouped
As @linkdotnet pointed out in the issue, files are processed one by one, even though
FileChangedEventArgs
supports multiple files at once. This behavior originates from the underlying Easy Markdown Editor and itsimageUploadFunction
, which handles only one file at a time. The relevant implementation is here:EasyMDE source.
On the Blazorise side, event handling follows a similar pattern to
FileEdit
, which maintains the same event arguments (Files
instead ofFile
). That said, I think we should improve this, at least by documenting it. Additionally, I believe I can "group" the individual calls from js into a single call to .NET.Unreachable Files
The current fixed implementation follows one flow—it keeps files in memory "forever". This is by design because Blazorise cannot effectively predict when a user will call
WriteToStream
.This issue could be mitigated by deleting the
blob
from the dictionary (where the files persist "forever") once it has been written to a stream. However, doing so would prevent the user from writing to the stream again or later:The implementation problem lies in the fact that the C# reference is not synchronized with its content on the js side, and there is currently no way to verify this from C# code.
(also) for this reason, the documentation includes a
try-catch
block around this logic. However, I think it would be better to streamline the solution with something likeTryToWriteToStreamAsync
...Is it worth improving that @stsrki ?