progress commit

This commit is contained in:
limited_dev 2023-01-27 23:50:12 +01:00
parent c04b9ac6f2
commit 01fe86113d

View file

@ -8,6 +8,7 @@
@using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Data.Repository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IWebHostEnvironment env
<div> <div>
<span>[</span> <span>[</span>
@ -23,9 +24,9 @@
<div> <div>
<div class="pd centered marg"> <div class="pd centered marg">
@if (image != null) @if (image != null)
{ {
<img class="formImage" src="@($"data:image/png;base64,{Convert.ToBase64String(image)}")" alt="No Image"/> <img class="formImage" src="@($"data:image/png;base64,{Convert.ToBase64String(image)}")" alt="No Image"/>
} }
</div> </div>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/> <InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
</div> </div>
@ -95,14 +96,20 @@
Console.WriteLine($"Smth changed!: {value}"); Console.WriteLine($"Smth changed!: {value}");
} }
private IBrowserFile selectedFile;
private async Task SingleUpload(InputFileChangeEventArgs e) private async Task SingleUpload(InputFileChangeEventArgs e)
{ {
/*
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
await e.File.OpenReadStream().CopyToAsync(ms); await e.File.OpenReadStream().CopyToAsync(ms);
var bytes = ms.ToArray(); var bytes = ms.ToArray();
image = bytes; image = bytes;
Console.WriteLine("File has been selected!"); Console.WriteLine("File has been selected!");
ms.Close(); ms.Close(); */
selectedFile = e.GetMultipleFiles()[0];
this.StateHasChanged();
} }
private Byte[] image; private Byte[] image;
@ -133,6 +140,18 @@
//TODO Add check if data is image //TODO Add check if data is image
if (selectedFile == null)
{
return;
}
Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 4); // max 2MB
var path = $"{env.WebRootPath}\\dynamic\\op\\{selectedFile.Name}";
FileStream fs = File.Create(path);
await stream.CopyToAsync(fs);
stream.Close();
fs.Close();
var imageToUpload = new ImageData var imageToUpload = new ImageData
{ {
Board = board.Tag, Board = board.Tag,