From 5269f5f6b20cde0c04b7c263d2f60b3ff1557539 Mon Sep 17 00:00:00 2001 From: UlrichB22 <97119703+UlrichB22@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:38:52 +0100 Subject: [PATCH] send_file: seek to the beginning of the file in any case --- src/moin/utils/send_file.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/moin/utils/send_file.py b/src/moin/utils/send_file.py index 31ae4c522..bf8bc432b 100644 --- a/src/moin/utils/send_file.py +++ b/src/moin/utils/send_file.py @@ -140,12 +140,15 @@ def send_file( # be extra careful as some file-like objects (like zip members) have a seek # and tell methods, but they just raise some exception (e.g. UnsupportedOperation) # instead of really doing what they are supposed to do (or just be missing). + seek_successful = False try: file.seek(0, 2) # seek to EOF + seek_successful = True fsize = file.tell() # tell position - file.seek(0, 0) # seek to start of file except Exception as e: logging.warning(f"Exception in send_file: {e}, data file {file.name.rsplit('/', maxsplit=1)[1]}") + if seek_successful: + file.seek(0, 0) # seek to start of file if fsize is not None: headers.add("Content-Length", fsize)