From 0e4067b3bc65d716e0b9cbd3813787d098b988d9 Mon Sep 17 00:00:00 2001 From: Caerol <> Date: Tue, 22 Oct 2024 02:50:53 +0300 Subject: [PATCH] 585 fix file overwrite --- iopaint/api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iopaint/api.py b/iopaint/api.py index 6725479..aac03f0 100644 --- a/iopaint/api.py +++ b/iopaint/api.py @@ -183,9 +183,12 @@ class Api: return self.app.add_api_route(path, endpoint, **kwargs) def api_save_image(self, file: UploadFile): - filename = file.filename + file_to_write = Path(file.filename) + if not file_to_write.is_file(): + return + origin_image_bytes = file.file.read() - with open(self.config.output_dir / filename, "wb") as fw: + with open(self.config.output_dir / file_to_write.name, "wb") as fw: fw.write(origin_image_bytes) def api_current_model(self) -> ModelInfo: