Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

58 lines (47 sloc) 1.59 KB
@page "/multi"
<h1>Multiple files</h1>
<p>A multi-file picker that displays information about selection and shows progress as each one is loaded.</p>
<InputFile multiple OnChange="HandleSelection" />
@if (selectedFiles != null)
{
foreach (var file in selectedFiles)
{
var isLoading = file.Data.Position > 0;
<div class="file-row">
<!-- File info -->
<div>
<h2>@file.Name</h2>
Size: <strong>@file.Size bytes</strong>;
Last modified: <strong>@file.LastModified.ToShortDateString()</strong>;
Type: <strong>@file.Type</strong>
</div>
<!-- Upload button -->
<button @onclick="() => LoadFile(file)" disabled="@isLoading">
@if (!isLoading)
{
<span>Load</span>
}
else
{
<span>Loaded @((100.0 * file.Data.Position / file.Size).ToString("0"))%</span>
}
</button>
</div>
}
}
@code {
IFileListEntry[] selectedFiles;
void HandleSelection(IFileListEntry[] files)
{
selectedFiles = files;
}
async Task LoadFile(IFileListEntry file)
{
// So the UI updates to show progress
file.OnDataRead += (sender, eventArgs) => InvokeAsync(StateHasChanged);
// Just load into .NET memory to show it can be done
// Alternatively it could be saved to disk, or parsed in memory, or similar
var ms = new MemoryStream();
await file.Data.CopyToAsync(ms);
}
}
You can’t perform that action at this time.