Hi folks,
I am trying to upload a file to a state container using the FileSelect component.
private async Task OnFileSelected(FileSelectEventArgs e)
{
try
{
foreach (var file in e.Files)
{
using var memoryStream = new MemoryStream();
byte[] buffer = new byte[81920]; // 80 KB buffer size
int bytesRead;
while ((bytesRead = await file.Stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await memoryStream.WriteAsync(buffer, 0, bytesRead);
}
byte[] fileBytes = memoryStream.ToArray();
// Store file in state container
await FileState.AddFileContentAsync(file.Name, fileBytes);
}
}
catch(Exception ex)
{
Console.WriteLine("Error uploading files " + ex.Message);
}
StateHasChanged();
}
Here file.Stream.ReadAsync is not working.
In Visual studio for the file.Steam property I am getting the following error message.
SYNCHRONOUS_FILESTREAM_READ_ERROR property
Synchronous actions on the file stream is not supported by the Blazor framework in Blazor Server-side apps due to the SignalR communication between the client and the host. Use the 'ReadAsync' method instead.
and the code does not continue to execute after the line while ((bytesRead = await file.Stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
I am trying to upload a file to a state container using the FileSelect component.
private async Task OnFileSelected(FileSelectEventArgs e)
{
try
{
foreach (var file in e.Files)
{
using var memoryStream = new MemoryStream();
byte[] buffer = new byte[81920]; // 80 KB buffer size
int bytesRead;
while ((bytesRead = await file.Stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await memoryStream.WriteAsync(buffer, 0, bytesRead);
}
byte[] fileBytes = memoryStream.ToArray();
// Store file in state container
await FileState.AddFileContentAsync(file.Name, fileBytes);
}
}
catch(Exception ex)
{
Console.WriteLine("Error uploading files " + ex.Message);
}
StateHasChanged();
}
Here file.Stream.ReadAsync is not working.
In Visual studio for the file.Steam property I am getting the following error message.
SYNCHRONOUS_FILESTREAM_READ_ERROR property
Synchronous actions on the file stream is not supported by the Blazor framework in Blazor Server-side apps due to the SignalR communication between the client and the host. Use the 'ReadAsync' method instead.
and the code does not continue to execute after the line while ((bytesRead = await file.Stream.ReadAsync(buffer, 0, buffer.Length)) > 0)