From 1ccc8dce3added764cda9eeec49359e1912ac0cd Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 22 Feb 2026 09:28:25 +0100 Subject: [PATCH] fix: load file content before generating attachment preview LoadFileByID() was called after the preview branch, so GetPreview() received a nil io.Reader causing a panic in image.Decode. --- pkg/routes/api/v1/task_attachment.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/routes/api/v1/task_attachment.go b/pkg/routes/api/v1/task_attachment.go index cc1e8ae69..cefce0243 100644 --- a/pkg/routes/api/v1/task_attachment.go +++ b/pkg/routes/api/v1/task_attachment.go @@ -184,6 +184,13 @@ func GetTaskAttachment(c *echo.Context) error { return err } + // Open the file so its content is available for preview generation and download + err = taskAttachment.File.LoadFileByID() + if err != nil { + _ = s.Rollback() + return err + } + // If the preview query parameter is set, get the preview (cached or generate) previewSize := models.GetPreviewSizeFromString(c.QueryParam("preview_size")) if previewSize != models.PreviewSizeUnknown && strings.HasPrefix(taskAttachment.File.Mime, "image") { @@ -193,13 +200,6 @@ func GetTaskAttachment(c *echo.Context) error { } } - // Open and send the file to the client - err = taskAttachment.File.LoadFileByID() - if err != nil { - _ = s.Rollback() - return err - } - if err := s.Commit(); err != nil { _ = s.Rollback() return err