Browse Source

Merge pull request #6109 from JoeyShapiro/dev

fix: disallow empty files
Timothy Jaeryang Baek 6 months ago
parent
commit
de1e29eed0

+ 6 - 0
backend/open_webui/apps/webui/routers/files.py

@@ -47,6 +47,12 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
         file_path = f"{UPLOAD_DIR}/{filename}"
 
         contents = file.file.read()
+        if len(contents) == 0:
+            raise HTTPException(
+                status_code=status.HTTP_400_BAD_REQUEST,
+                detail=ERROR_MESSAGES.EMPTY_CONTENT,
+            )
+
         with open(file_path, "wb") as f:
             f.write(contents)
             f.close()

+ 5 - 0
src/lib/components/workspace/Knowledge/Collection.svelte

@@ -124,6 +124,11 @@
 			itemId: tempItemId
 		};
 
+		if (fileItem.size == 0) {
+			toast.error($i18n.t('File must have content to be uploaded'));
+			return null;
+		}
+
 		knowledge.files = [...(knowledge.files ?? []), fileItem];
 
 		// Check if the file is an audio file and transcribe/convert it to text file