Added workaround using base64 embedding

This commit is contained in:
Thorsten Sommer 2025-12-30 14:27:13 +01:00
parent 6cf14a57c7
commit 3220c8970f
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,7 @@
@if (this.Document?.IsImage ?? false)
{
<MudTabPanel Text="@T("Image View")" Icon="@Icons.Material.Filled.Image">
<MudImage ObjectFit="ObjectFit.ScaleDown" Src="@this.Document.FilePathAsUrl"/>
<MudImage ObjectFit="ObjectFit.ScaleDown" Src="@this.imageDataUrl"/>
</MudTabPanel>
}
else

View File

@ -30,13 +30,29 @@ public partial class DocumentCheckDialog : MSGComponentBase
[Inject]
private ILogger<DocumentCheckDialog> Logger { get; init; } = null!;
private string imageDataUrl = string.Empty;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && this.Document is not null)
{
try
{
if (!this.Document.IsImage)
if (this.Document.IsImage)
{
// Load image as Base64 data URL since browsers cannot access local file:// URLs:
if (this.Document is FileAttachmentImage imageAttachment)
{
var (success, base64Content) = await imageAttachment.TryAsBase64();
if (success)
{
var mimeType = imageAttachment.DetermineMimeType();
this.imageDataUrl = ImageHelpers.ToDataUrl(base64Content, mimeType);
this.StateHasChanged();
}
}
}
else
{
var fileContent = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService);
this.FileContent = fileContent;