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
@inject NavigationManager NavigationManager
@inject IWebHostEnvironment env
<div>
<span>[</span>
@ -23,9 +24,9 @@
<div>
<div class="pd centered marg">
@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>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
</div>
@ -95,14 +96,20 @@
Console.WriteLine($"Smth changed!: {value}");
}
private IBrowserFile selectedFile;
private async Task SingleUpload(InputFileChangeEventArgs e)
{
/*
MemoryStream ms = new MemoryStream();
await e.File.OpenReadStream().CopyToAsync(ms);
var bytes = ms.ToArray();
image = bytes;
Console.WriteLine("File has been selected!");
ms.Close();
ms.Close(); */
selectedFile = e.GetMultipleFiles()[0];
this.StateHasChanged();
}
private Byte[] image;
@ -132,7 +139,19 @@
}
//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
{
Board = board.Tag,