-
Not sure if this is a FluentUI issue or a general Blazor issue. I try to let the user upload a csv file, which I will parse and convert to a JSON and send to an API. I'm using FluentInputFile: <FluentInputFile Id="my-file-uploader"
Mode="InputFileMode.Stream"
Multiple="false"
MaximumFileCount="1"
MaximumFileSize="@(10*1024*1024)"
Accept="text/csv"
@bind-ProgressPercent="@ProgressPercent"
OnCompleted="@OnCompletedAsync"
OnFileUploaded="@OnFileUploadedAsync"
Style="height: 100px; border: 2px dashed var(--accent-fill-rest);">
<ChildContent>
<label for="my-file-uploader">
<FluentIcon Value="@(new @Icons.Regular.Size24.ArrowUpload())" />
</label>
<div>
Drag files here you wish to upload,
or <label for="my-file-uploader">browse</label>
for them<span style="color: red;">*</span>.
<br />
<em>Maximaal 1 bestand per keer.</em>
</div>
</ChildContent>
</FluentInputFile>
@if (UploadedFile is not null) {
<h4>Verwerkt bestand:</h4>
<p>
<b>@UploadedFile.Name</b> 🔹
@($"{decimal.Divide(UploadedFile.Size, 1024):N} KB") 🔹
@UploadedFile.ContentType 🔹
@UploadedFile.LocalFile?.FullName
@UploadedFile.ErrorMessage
</p>
} private async Task OnCompletedAsync(IEnumerable<FluentInputFileEventArgs> files)
{
// Wait 3 seconds before to reset the progress bar.
await Task.Delay(3000, CancellationToken.None).ConfigureAwait(false);
ProgressPercent = 0;
}
private async Task OnFileUploadedAsync(FluentInputFileEventArgs file)
{
ProgressPercent = file.ProgressPercent;
ProgressTitle = file.ProgressTitle;
UploadedFile = file;
// Read the stream:
await using (var stream = file.LocalFile?.OpenRead())
{
if (stream != null)
{
using var reader = new StreamReader(stream);
var csvData = (await reader.ReadToEndAsync(CancellationToken.None).ConfigureAwait(false))
.Split('\n');
// Use the csvData list as needed
AlertService.DialogSuccess($"CSV file uploaded successfully with {csvData.Length} rows.");
}
}
} I put a breakpoint at the first line in OnCompletedAsync and OnFileUploadedAsync.
Without breakpoints the debug session is stopped as well. To make it even weirder. When I deploy to Azure I can upload and the website doesn't stop. Even the file name and file size are shown in the browser. Does anybody have experienced this before? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seems to be an issue with my browser. I was using Brave for debugging. I also updated my method that reads the stream: private async Task OnFileUploadedAsync(FluentInputFileEventArgs file)
{
ProgressPercent = file.ProgressPercent;
ProgressTitle = file.ProgressTitle;
if (file.Stream is null) return;
// Read the stream:
using var reader = new StreamReader(file.Stream);
var csvData = (await reader.ReadToEndAsync(CancellationToken.None).ConfigureAwait(false))
.Split('\n');
// Use the csvData list as needed
AlertService.DialogSuccess($"CSV file uploaded successfully with {csvData.Length} rows.");
} Hopefully this will help others. |
Beta Was this translation helpful? Give feedback.
It seems to be an issue with my browser. I was using Brave for debugging.
I now switched the Edge and the debug session stays active and I can debug my code.
Not sure why, both browsers are Chrome-based.
I also updated my method that reads the stream: