fix: stage zip downloads to temp file and improve file serving headers

Write zip to a temporary file before serving to enable correct content-length, range requests, and proper cache-control headers. Additionally, handle negative object sizes by falling back to file metadata for content-length.
This commit is contained in:
2026-06-15 21:52:33 +03:00
parent e2cf7115b7
commit dc4aee8ca2
5 changed files with 114 additions and 10 deletions

View File

@@ -1028,9 +1028,13 @@ func (s *UploadService) RecordDownload(boxID string) error {
})
}
func (s *UploadService) WriteZip(w io.Writer, box Box) error {
func (s *UploadService) WriteZip(w io.Writer, box Box) (err error) {
archive := zip.NewWriter(w)
defer archive.Close()
defer func() {
if closeErr := archive.Close(); err == nil {
err = closeErr
}
}()
for _, file := range box.Files {
object, err := s.OpenFileObject(context.Background(), box, file)