119 lines
2.9 KiB
Plaintext
119 lines
2.9 KiB
Plaintext
@page "/upload"
|
|
@using System
|
|
@using System.IO
|
|
@using System.Globalization
|
|
@using Microsoft.AspNetCore.Hosting
|
|
@using Microsoft.Extensions.Logging
|
|
@using System.Linq
|
|
@using CsvHelper
|
|
@using CsvHelper.Configuration
|
|
@using CsvHelper.Configuration.Attributes
|
|
@*@inject ILogger<FileUpload1> Logger*@
|
|
@inject ILogger<Upload> Logger
|
|
@inject IWebHostEnvironment Environment
|
|
|
|
<h3>Upload Files</h3>
|
|
|
|
<p>
|
|
<label>
|
|
Max file size:
|
|
<input type="number" @bind="maxFileSize" />
|
|
</label>
|
|
</p>
|
|
|
|
<p>
|
|
<label>
|
|
Max allowed files:
|
|
<input type="number" @bind="maxAllowedFiles" />
|
|
</label>
|
|
</p>
|
|
|
|
<p>
|
|
<label>
|
|
Upload up to @maxAllowedFiles of up to @maxFileSize bytes:
|
|
<InputFile OnChange="@LoadFiles" multiple />
|
|
</label>
|
|
</p>
|
|
|
|
@if (isLoading)
|
|
{
|
|
<p>Uploading...</p>
|
|
}
|
|
else
|
|
{
|
|
<ul>
|
|
@foreach (var file in loadedFiles)
|
|
{
|
|
<li>
|
|
<ul>
|
|
<li>Name: @file.Name</li>
|
|
<li>Last modified: @file.LastModified.ToString()</li>
|
|
<li>Size (bytes): @file.Size</li>
|
|
<li>Content type: @file.ContentType</li>
|
|
</ul>
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
|
|
@code {
|
|
private List<IBrowserFile> loadedFiles = new();
|
|
private long maxFileSize = 1024 * 15;
|
|
private int maxAllowedFiles = 3;
|
|
private bool isLoading;
|
|
|
|
private async Task LoadFiles(InputFileChangeEventArgs e)
|
|
{
|
|
isLoading = true;
|
|
loadedFiles.Clear();
|
|
|
|
foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
|
|
{
|
|
try
|
|
{
|
|
loadedFiles.Add(file);
|
|
|
|
var trustedFileNameForFileStorage = Path.GetRandomFileName();
|
|
var path = Path.Combine(Environment.ContentRootPath,
|
|
Environment.EnvironmentName, "unsafe_uploads",
|
|
trustedFileNameForFileStorage);
|
|
|
|
await using FileStream fs = new(path, FileMode.Create);
|
|
await file.OpenReadStream(maxFileSize).CopyToAsync(fs);
|
|
|
|
//using (var csvReader = new CsvReader(fs, CultureInfo.InvariantCulture));
|
|
//{
|
|
// var records = CsvReader.GetRecords<dynamic>().ToList();
|
|
|
|
//}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError("File: {Filename} Error: {Error}",
|
|
file.Name, ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
isLoading = false;
|
|
}
|
|
|
|
public class RocketLaunch
|
|
{
|
|
[Name("flight_number") ]
|
|
public int FlightNumber { get; set; }
|
|
|
|
[Name("name") ]
|
|
public string MissionName { get; set; }
|
|
|
|
[Name("launch_date") ]
|
|
public DateTime LaunchDate { get; set; }
|
|
|
|
[Name("success") ]
|
|
public bool Succeded { get; set; }
|
|
|
|
[Name("booster_recovered") ]
|
|
public bool DidLand { get; set; }
|
|
}
|
|
} |