FileInfoStream throws NotImplementedException

1 Answer 111 Views
FileSelect
Johannes
Top achievements
Rank 2
Johannes asked on 02 Nov 2022, 10:51 AM | edited on 02 Nov 2022, 10:51 AM

Hi,

I use the FileSelect component and when using the FileInfoStream object with another component that isn't asynchronous I get a NotImplementedException for the Read() method.

Do you plan to implement these methods to ensure compatibility with synchronous components?

Thanks!

System.NotImplementedException: The method or operation is not implemented.
   at Telerik.Blazor.Components.FileSelect.Stream.FileInfoStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadLine()

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 04 Nov 2022, 04:07 PM

Hello Johannes,

Blazor Server does not support synchronous IO reading of streams, that's why we have overridden some of the Stream methods in our code.

The same limitation exists for the standard Blazor InputFile component. I also recommend this post and the pages it links.

A possible workaround is to copy the FileSelect Stream to another one and work with that instead.

@using System.IO

<TelerikFileSelect OnSelect="@ReadSelectedFiles" />

@code {
    private async Task ReadSelectedFiles(FileSelectEventArgs args)
    {
        foreach (var file in args.Files)
        {
            var ms = new MemoryStream();
            await file.Stream.CopyToAsync(ms);

            var byteArray = new byte[file.Size];

            ms.Seek(0, SeekOrigin.Begin); // not possible with file.Stream
            ms.Read(byteArray); // not possible with file.Stream
        }
    }
}

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
FileSelect
Asked by
Johannes
Top achievements
Rank 2
Answers by
Dimo
Telerik team
Share this question
or