Code previously used in .net 5.0.
<BlazorFileUploader.InputFile OnChange="HandleFileSelected" />
public async Task HandleFileSelected(IFileListEntry[] files)
{
if (files.Count() > 0)
{
file = files.FirstOrDefault();
using (var ms = new MemoryStream())
{
await file.Data.CopyToAsync(ms);
_fileBytes = ms.ToArray();
fileModelToInsert.FileNm = file.Name;
fileModelToInsert.FileType = file.Type;
await jsRuntime.InvokeVoidAsync("alert", "confirm.");
fileModelToInsert.FileData = Convert.ToBase64String(_fileBytes);
}
}
}
I wrote it using the BlazorFileUploader package. Upgrade it to .net 8.0, Blazor Upload Component | Free UI Components by Radzen
I referred to this site. The question here is that FileName can be imported, but I tried to convert the file extension and most important file information into bytes and then convert it into convert64string, but I don't know where the file data is.