|
|
|
@@ -11,9 +11,6 @@ |
|
|
|
@inject MasterDataService MasterDataService
|
|
|
|
@inject IMatToaster Toaster
|
|
|
|
|
|
|
|
@*@using Tewr.Blazor.FileReader
|
|
|
|
@inject IFileReaderService fileReaderService;*@
|
|
|
|
|
|
|
|
|
|
|
|
<div class="row px-3 h-100">
|
|
|
|
<div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
|
|
|
|
@@ -29,7 +26,7 @@ |
|
|
|
<div class="mat-layout-grid-inner">
|
|
|
|
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-1 justify-content-center" style="text-align: center">
|
|
|
|
<div>
|
|
|
|
<InputFile class="inputFile" id="camera" type="file" name="camera" accept="image/*" capture="user" OnChange="@OnFileSelection" />
|
|
|
|
<InputFile class="inputFile" id="camera" type="file" name="camera" accept="image/*" capture="environment" OnChange="@OnGatheringPicture" />
|
|
|
|
<MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
|
|
|
|
<label for="camera">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
|
|
|
|
@@ -41,8 +38,8 @@ |
|
|
|
</MatRipple>
|
|
|
|
</div>
|
|
|
|
<div style="margin-top:1rem">
|
|
|
|
@*<input @ref="inputTypeFileElement" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" class="inputFile" @onchange="ReadFile" />*@
|
|
|
|
<InputFile id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" class="inputFile" OnChange="@OnFileSelection" />
|
|
|
|
@* <input @ref="inputTypeFileElement" class="inputFile" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" @onchange="ReadFile" />*@
|
|
|
|
<InputFile class="inputFile" id="file" type="file" name="file" accept="image/x-png,image/jpeg,image/gif" OnChange="@OnGatheringPicture" />
|
|
|
|
<MatRipple class="inputfile-mat-ripple" Color="@MatRippleColor.Default">
|
|
|
|
<label for="file">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" width="48px" height="48px" viewBox="0 0 24 24" fill="#000000">
|
|
|
|
@@ -55,9 +52,13 @@ |
|
|
|
</div>
|
|
|
|
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
|
|
|
|
<div>
|
|
|
|
<MatCard Class="demo-mat-card">
|
|
|
|
<MatCard Id="bikePic" Class="fv-mat-card">
|
|
|
|
<MatCardContent>
|
|
|
|
<MatCardMedia Square="true" Class="" ImageUrl="@imgUrl" />
|
|
|
|
<MatCardMedia Square="true" Class="" ImageUrl="@imgUrl">
|
|
|
|
@if (loading) {
|
|
|
|
<MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Medium" />
|
|
|
|
}
|
|
|
|
</MatCardMedia>
|
|
|
|
</MatCardContent>
|
|
|
|
</MatCard>
|
|
|
|
</div>
|
|
|
|
@@ -69,7 +70,7 @@ |
|
|
|
</div>
|
|
|
|
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-3">
|
|
|
|
<div>
|
|
|
|
<MatCard Class="demo-mat-card">
|
|
|
|
<MatCard Id="OSM" Class="fv-mat-card">
|
|
|
|
<MatCardContent>
|
|
|
|
<MatCardMedia Square="true" Class="" />
|
|
|
|
</MatCardContent>
|
|
|
|
@@ -146,14 +147,15 @@ |
|
|
|
[Parameter(CaptureUnmatchedValues = true)]
|
|
|
|
public IDictionary<string, object> Attributes { get; set; }
|
|
|
|
|
|
|
|
private static int MAX_FILE_SIZE = 4000000;
|
|
|
|
private static long MAX_FILE_SIZE = 3145728; //3MB
|
|
|
|
|
|
|
|
private ColorItem selectedColor;
|
|
|
|
private BicycleType selectedBcType;
|
|
|
|
private ElementReference inputTypeFileElement;
|
|
|
|
private string imgUrl = string.Empty;
|
|
|
|
private Boolean loading = false;
|
|
|
|
|
|
|
|
protected async override void OnInitialized() {
|
|
|
|
|
|
|
|
Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name);
|
|
|
|
Console.WriteLine("Current language is {0}.", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToUpper());
|
|
|
|
|
|
|
|
@@ -202,44 +204,59 @@ |
|
|
|
return @FromRoute == "Found" ? i18n.GetString("PlaceOfDiscovery") : i18n.GetString("PlaceOfLoss");
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task OnFileSelection(InputFileChangeEventArgs e) {
|
|
|
|
private async Task OnGatheringPicture(InputFileChangeEventArgs e) {
|
|
|
|
IBrowserFile imgFile = e.File;
|
|
|
|
var buffers = new byte[imgFile.Size];
|
|
|
|
try {
|
|
|
|
imgUrl = string.Empty;
|
|
|
|
loading = true;
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
await imgFile.OpenReadStream(MAX_FILE_SIZE).ReadAsync(buffers);
|
|
|
|
string imageType = imgFile.ContentType;
|
|
|
|
imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffers)}";
|
|
|
|
} catch (IOException ex) {
|
|
|
|
Console.WriteLine("Ex.Meesage is: {0}.", ex.Message);
|
|
|
|
Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / 1000));
|
|
|
|
Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024)));
|
|
|
|
} finally {
|
|
|
|
loading = false;
|
|
|
|
StateHasChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//public async Task ReadFile() {
|
|
|
|
// foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) {
|
|
|
|
// IFileInfo fileInfo = await file.ReadFileInfoAsync();
|
|
|
|
|
|
|
|
public void Show(MatToastType type, string title, string message, string icon = "") {
|
|
|
|
Toaster.Add(message, type, title, icon);
|
|
|
|
}
|
|
|
|
// if (fileInfo.Size > MAX_FILE_SIZE) {
|
|
|
|
|
|
|
|
//*******
|
|
|
|
// Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024*1024)));
|
|
|
|
|
|
|
|
//private ElementReference inputTypeFileElement;
|
|
|
|
// } else {
|
|
|
|
// imgUrl = string.Empty;
|
|
|
|
// loading = true;
|
|
|
|
// StateHasChanged();
|
|
|
|
|
|
|
|
//public async Task ReadFile() {
|
|
|
|
// foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) {
|
|
|
|
// IFileInfo fileInfo = await file.ReadFileInfoAsync();
|
|
|
|
// byte[] buffer = new byte[fileInfo.Size];
|
|
|
|
// using (MemoryStream memoryStream = await file.CreateMemoryStreamAsync(4096)) {
|
|
|
|
// int bytesRead = 0;
|
|
|
|
// int offset = 0;
|
|
|
|
// do {
|
|
|
|
// bytesRead = memoryStream.Read(buffer, offset, 4096);
|
|
|
|
// offset = offset + bytesRead;
|
|
|
|
// } while (bytesRead < 4096);
|
|
|
|
|
|
|
|
// string imageType = fileInfo.Type;
|
|
|
|
// imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
|
|
|
|
// byte[] buffer = new byte[fileInfo.Size];
|
|
|
|
|
|
|
|
// await using (Stream stream = await file.OpenReadAsync()) {
|
|
|
|
// buffer = new Byte[stream.Length];
|
|
|
|
// await stream.ReadAsync(buffer);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// using (MemoryStream memoryStream = await file.CreateMemoryStreamAsync(4096)) {
|
|
|
|
// memoryStream.Read(buffer);
|
|
|
|
// string imageType = fileInfo.Type;
|
|
|
|
// loading = false;
|
|
|
|
// imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
|
|
|
|
// StateHasChanged();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
public void Show(MatToastType type, string title, string message, string icon = "") {
|
|
|
|
Toaster.Add(message, type, title, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|