From 41b511b322a9d0ef66180d3620204d3292fca4bd Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 4 Feb 2026 19:37:49 +0100 Subject: [PATCH] fix(files): seek to start before writing for consistent behavior Both local and S3 backends now seek to position 0 before writing, ensuring consistent behavior regardless of the reader's current offset. --- pkg/files/files.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/files/files.go b/pkg/files/files.go index 9b777f2dd..d7c118a0a 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -153,8 +153,15 @@ func (f *File) Delete(s *xorm.Session) (err error) { return keyvalue.DecrBy(metrics.FilesCountKey, 1) } -// writeToStorage writes content to the given path, handling both local and S3 backends +// writeToStorage writes content to the given path, handling both local and S3 backends. +// The reader is always seeked to position 0 before writing to ensure consistent behavior. func writeToStorage(path string, content io.ReadSeeker, size uint64) error { + // Seek to start to ensure we write the complete content regardless of + // the reader's current position + if _, err := content.Seek(0, io.SeekStart); err != nil { + return fmt.Errorf("failed to seek to start of content: %w", err) + } + if s3Client == nil { return afs.WriteReader(path, content) }