From 1680e6527af2b76a3a1bc7f67a66edd40a82f977 Mon Sep 17 00:00:00 2001 From: Silow <99187811+Silow9@users.noreply.github.com> Date: Fri, 28 Mar 2025 14:50:45 +0800 Subject: [PATCH] Update index.tsx Made modification to make the system support uploading a folder so that the system recursively retrieves all files within the folder and sequentially adds them to the upload list. Add a button to upload the folder. By the way, remember to modify the Knowledge Configuration and NGINX_CLIENT_MAX_BODY_SIZE in the file named .env.example in main menu to ensure the uploading is allowed for size limitation. --- .../datasets/create/file-uploader/index.tsx | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/web/app/components/datasets/create/file-uploader/index.tsx b/web/app/components/datasets/create/file-uploader/index.tsx index 63bd554215..092f2f0ab5 100644 --- a/web/app/components/datasets/create/file-uploader/index.tsx +++ b/web/app/components/datasets/create/file-uploader/index.tsx @@ -47,6 +47,10 @@ const FileUploader = ({ const dropRef = useRef(null) const dragRef = useRef(null) const fileUploader = useRef(null) + + // For upload folder + const dirUploader = useRef(null) + const hideUpload = notSupportBatchUpload && fileList.length > 0 const { data: fileUploadConfigResponse } = useSWR({ url: '/files/upload' }, fetchFileUploadConfig) @@ -214,6 +218,12 @@ const FileUploader = ({ fileUploader.current.click() } + // click on button, use folder upload + const selectFolderHandle = () => { + if (dirUploader.current) + dirUploader.current.click() + } + const removeFile = (fileID: string) => { if (fileUploader.current) fileUploader.current.value = '' @@ -223,7 +233,15 @@ const FileUploader = ({ } const fileChangeHandle = useCallback((e: React.ChangeEvent) => { const files = [...(e.target.files ?? [])] as File[] - initialUpload(files.filter(isValid)) + const validFiles = files.filter(isValid) + initialUpload(validFiles) + }, [isValid, initialUpload]) + + // Callback for folder upload + const folderChangeHandle = useCallback((e: React.ChangeEvent) => { + const files = [...(e.target.files ?? [])] as File[] + const validFiles = files.filter(isValid) + initialUpload(validFiles) }, [isValid, initialUpload]) const { theme } = useTheme() @@ -245,15 +263,36 @@ const FileUploader = ({ return (
{!hideUpload && ( - + <> + + {/* folder uploader */} + + + )} + + {/* give user a “Upload Folder” button */} + {!hideUpload && ( + )}
{t('datasetCreation.stepOne.uploader.title')}