From 76decdba2a6dd49768e052bfb404ef72a1dcb447 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 28 Dec 2024 17:40:00 -0800 Subject: [PATCH] fix: delete file --- backend/open_webui/routers/files.py | 2 +- backend/open_webui/routers/knowledge.py | 7 ------- backend/open_webui/storage/provider.py | 4 +++- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/backend/open_webui/routers/files.py b/backend/open_webui/routers/files.py index 3b1ba2945..9e36d98b7 100644 --- a/backend/open_webui/routers/files.py +++ b/backend/open_webui/routers/files.py @@ -348,7 +348,7 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user)): result = Files.delete_file_by_id(id) if result: try: - Storage.delete_file(file.filename) + Storage.delete_file(file.path) except Exception as e: log.exception(e) log.error(f"Error deleting files") diff --git a/backend/open_webui/routers/knowledge.py b/backend/open_webui/routers/knowledge.py index 04ebcf507..87e8599ed 100644 --- a/backend/open_webui/routers/knowledge.py +++ b/backend/open_webui/routers/knowledge.py @@ -419,13 +419,6 @@ def remove_file_from_knowledge_by_id( collection_name=knowledge.id, filter={"file_id": form_data.file_id} ) - result = VECTOR_DB_CLIENT.query( - collection_name=knowledge.id, - filter={"file_id": form_data.file_id}, - ) - - Files.delete_file_by_id(form_data.file_id) - if knowledge: data = knowledge.data or {} file_ids = data.get("file_ids", []) diff --git a/backend/open_webui/storage/provider.py b/backend/open_webui/storage/provider.py index 76e4fc48f..ae3347682 100644 --- a/backend/open_webui/storage/provider.py +++ b/backend/open_webui/storage/provider.py @@ -147,8 +147,10 @@ class StorageProvider: return self._get_file_from_s3(file_path) return self._get_file_from_local(file_path) - def delete_file(self, filename: str) -> None: + def delete_file(self, file_path: str) -> None: """Deletes a file either from S3 or the local file system.""" + filename = file_path.split("/")[-1] + if self.storage_provider == "s3": self._delete_from_s3(filename)