fix: add Content-Disposition attachment header to task attachment downloads

Set Content-Disposition to "attachment" instead of "inline" so browsers
trigger a file download with the correct filename. Also move shared
response headers (Content-Type, Content-Length, Last-Modified) out of
the S3-specific branch so they apply to both storage backends.
This commit is contained in:
kolaente
2026-02-21 23:19:26 +01:00
parent 519f66a51f
commit 4915f535d0

View File

@@ -204,21 +204,18 @@ func GetTaskAttachment(c *echo.Context) error {
_ = s.Rollback()
return err
}
c.Response().Header().Set("Content-Disposition", "attachment; filename=\""+taskAttachment.File.Name+"\"")
c.Response().Header().Set("Content-Type", taskAttachment.File.Mime)
c.Response().Header().Set("Content-Length", strconv.FormatUint(taskAttachment.File.Size, 10))
c.Response().Header().Set("Last-Modified", taskAttachment.File.Created.UTC().Format(http.TimeFormat))
if config.FilesType.GetString() == "s3" {
// s3 files cannot use http.ServeContent as it requires a Seekable file
// Set response headers
c.Response().Header().Set("Content-Type", taskAttachment.File.Mime)
c.Response().Header().Set("Content-Disposition", "inline; filename=\""+taskAttachment.File.Name+"\"")
c.Response().Header().Set("Content-Length", strconv.FormatUint(taskAttachment.File.Size, 10))
c.Response().Header().Set("Last-Modified", taskAttachment.File.Created.UTC().Format(http.TimeFormat))
// Stream the file content directly to the response
// so we stream the file content directly to the response
_, err = io.Copy(c.Response(), taskAttachment.File.File)
if err != nil {
return err
}
} else {
http.ServeContent(c.Response(), c.Request(), taskAttachment.File.Name, taskAttachment.File.Created, taskAttachment.File.File)
return err
}
http.ServeContent(c.Response(), c.Request(), taskAttachment.File.Name, taskAttachment.File.Created, taskAttachment.File.File)
return nil
}