SteveSandersonMS / BlazorInputFile

A file input component for Blazor applications
250 stars 75 forks source link

CopyToAsync hangs in provided sample project #33

Open sgerendasy opened 4 years ago

sgerendasy commented 4 years ago

In the usage information blog post there is an example of a multiple file upload with this source code. In the blog post there is a gif demonstration which shows three files being asynchronously copied to a MemoryStream.

If you begin each copy to MemoryStream before any other files finish copying, this process works fine. However, if you call await file.Data.CopyToAsync(ms) after any other file has finished copying to MemoryStream, the copy hangs after getting ~500kB copied.

You can verify this by cloning the repo and running the sample program with the MultiFile.razor page. Select two or more files to upload, then click the Load button on one of them. Wait until that file is 100% loaded. Then click Load on another file. It will hang.

This is a problem for me because I have a form where 3 different files get selected, using 3 different <InputFile> components. The files begin uploading as soon as their selected, which involves reading the Stream in file.Data. If the user selects a 2nd or 3rd file after a file has finished uploading the newly selected file fails to upload. The program simply hangs.

I have been using files that are 3-50MB in size, which is what I expect the file size range to be in production.

paulallington commented 4 years ago

I am experiencing the same issue with just 1 . with a 1MB file the CopyToAsync hangs for around 3-5 seconds.

Boglen commented 4 years ago

Confirm. it hangs when i press another upload after all previous uploads have finished. image

RealHabix commented 4 years ago

do a ms.Dispose() as last statement

sgerendasy commented 4 years ago

Thank you @RealHabix, ms.Dispose() did the trick.