From 17c60d0bdf2948a8c55717b34d3231df7cbc141d Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 11 Apr 2021 11:41:45 +0200 Subject: file_storage.filesystem: Close temp file after save This will ensure the file content is flushed and lets us get the actual file size, which will fix very small files being stored with size == 0. --- fbin/file_storage/filesystem.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fbin/file_storage/filesystem.py b/fbin/file_storage/filesystem.py index 87d908e..b132264 100644 --- a/fbin/file_storage/filesystem.py +++ b/fbin/file_storage/filesystem.py @@ -36,6 +36,7 @@ class Storage(BaseStorage): else: temp = tempfile.NamedTemporaryFile(prefix='upload_', dir=self.app.config['FILE_DIRECTORY'], delete=False) uploaded_file.save(temp.file) + temp.close() temp_path = temp.name size = os.path.getsize(temp_path) new_path = self._get_path(file_hash) -- cgit v1.2.3