diff --git a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx index bd22a0ee..8c692e14 100644 --- a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx +++ b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx @@ -237,6 +237,16 @@ export const ChatInputArea = forwardRef((pr ? Array.from(nonImageFiles).concat(Array.from(attachedFiles || [])) : Array.from(attachedFiles || []); + // Ensure files are below size limit (10 MB) + for (let i = 0; i < newFiles.length; i++) { + if (newFiles[i].size > 10 * 1024 * 1024) { + setWarning( + `File ${newFiles[i].name} is too large. Please upload files smaller than 10 MB.`, + ); + return; + } + } + const dataTransfer = new DataTransfer(); newFiles.forEach((file) => dataTransfer.items.add(file)); setAttachedFiles(dataTransfer.files); diff --git a/src/khoj/routers/api_content.py b/src/khoj/routers/api_content.py index eb808c22..40a1fb78 100644 --- a/src/khoj/routers/api_content.py +++ b/src/khoj/routers/api_content.py @@ -384,10 +384,25 @@ async def convert_documents( files: List[UploadFile], client: Optional[str] = None, ): + MAX_FILE_SIZE_MB = 10 # 10MB limit + MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024 + converted_files = [] supported_files = ["org", "markdown", "pdf", "plaintext", "docx"] for file in files: + # Check file size first + file_size = 0 + content = await file.read() + file_size = len(content) + await file.seek(0) # Reset file pointer + + if file_size > MAX_FILE_SIZE_BYTES: + logger.warning( + f"Skipped converting oversized file ({file_size / 1024 / 1024:.1f}MB) sent by {client} client: {file.filename}" + ) + continue + file_data = get_file_content(file) if file_data.file_type in supported_files: extracted_content = (