56 lines
1.8 KiB
Plaintext
56 lines
1.8 KiB
Plaintext
@inject NavigationManager NavigationManager
|
|
|
|
<div id="overviewDemoDropZone" class="card custom-drop-zone rounded-3 w-100 m-0">
|
|
<span class="drop-file-icon mb-3"></span>
|
|
<span class="drop-file-label" >Drag and Drop File Here</span><span class="m-1">or</span>
|
|
<DxButton Id="overviewDemoSelectButton"
|
|
CssClass="m-1"
|
|
RenderStyle="ButtonRenderStyle.Primary"
|
|
Text="Select File" />
|
|
</div>
|
|
<DxFileInput
|
|
Visible="@UploadVisible"
|
|
ExternalSelectButtonCssSelector="#overviewDemoSelectButton"
|
|
ExternalDropZoneCssSelector="#overviewDemoDropZone"
|
|
ExternalDropZoneDragOverCssClass="custom-drop-zone-hover"
|
|
MaxFileSize="15000000"
|
|
AllowedFileExtensions="_allowedExtensions"
|
|
AcceptedFileTypes="_acceptedFileTypes"
|
|
FilesUploading="FilesUploading"
|
|
SelectedFilesChanged="@SelectedFilesChanged">
|
|
</DxFileInput>
|
|
|
|
<div class="upload-validation-text info-text">
|
|
Uploads are limited to a single file up to 15 MB.
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public Func<byte[], Task>? OnFileUploaded { get; set; }
|
|
|
|
bool UploadVisible { get; set; } = false;
|
|
|
|
readonly List<string> _allowedExtensions = new List<string> { ".jpg", ".jpeg", ".gif", ".png", ".pdf", ".json" };
|
|
readonly List<string> _acceptedFileTypes = new List<string> { "application/json", "application/pdf", "application/jpeg" };
|
|
|
|
byte[] FileBytes { get; set; }
|
|
|
|
protected void SelectedFilesChanged(IEnumerable<UploadFileInfo> files)
|
|
{
|
|
//InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async Task FilesUploading(FilesUploadingEventArgs args)
|
|
{
|
|
foreach (var file in args.Files)
|
|
{
|
|
using var stream = new System.IO.MemoryStream();
|
|
await file.OpenReadStream(file.Size).CopyToAsync(stream);
|
|
|
|
if (OnFileUploaded != null) await OnFileUploaded(stream.ToArray());
|
|
}
|
|
}
|
|
protected string GetUploadUrl(string url)
|
|
{
|
|
return NavigationManager.ToAbsoluteUri(url).AbsoluteUri;
|
|
}
|
|
} |