diff --git a/app/MindWork AI Studio/Chat/FileAttachment.cs b/app/MindWork AI Studio/Chat/FileAttachment.cs index eaf9d399..cf4b81fe 100644 --- a/app/MindWork AI Studio/Chat/FileAttachment.cs +++ b/app/MindWork AI Studio/Chat/FileAttachment.cs @@ -36,9 +36,9 @@ public record FileAttachment(FileAttachmentType Type, string FileName, string Fi public bool IsImage { get; } = Type == FileAttachmentType.IMAGE; /// - /// Gets the file path formatted as a file URL (file:///). + /// Gets the file path for loading the file from the web browser-side (Blazor). /// - public string FilePathAsUrl { get; } = $"file:///{FilePath.Replace('\\', '/')}"; + public string FilePathAsUrl { get; } = FileHandler.CreateFileUrl(FilePath); /// /// Gets a value indicating whether the file still exists on the file system. diff --git a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor index 48d2ac4b..2d1f9b09 100644 --- a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor +++ b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor @@ -31,7 +31,7 @@ @if (this.Document?.IsImage ?? false) { - + } else diff --git a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs index 557c5f87..4bf306f1 100644 --- a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs @@ -30,41 +30,25 @@ public partial class DocumentCheckDialog : MSGComponentBase [Inject] private ILogger 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) - { - // 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 + if (!this.Document.IsImage) { var fileContent = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService); this.FileContent = fileContent; - this.StateHasChanged(); } } catch (Exception ex) { this.Logger.LogError(ex, "Failed to load file content from '{FilePath}'", this.Document); this.FileContent = string.Empty; - this.StateHasChanged(); } + + this.StateHasChanged(); } else if (firstRender) this.Logger.LogWarning("Document check dialog opened without a valid file path.");