Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Add file type validation to paste upload (#28017)

Gen Sato19c92fd670ba
diff --git a/web/app/components/base/file-uploader/hooks.ts b/web/app/components/base/file-uploader/hooks.ts
index 9675123fe70..521ecdbafda 100644
--- a/web/app/components/base/file-uploader/hooks.ts
+++ b/web/app/components/base/file-uploader/hooks.ts
@@ -305,9 +305,23 @@ export const useFile = (fileConfig: FileUpload) => {
const text = e.clipboardData?.getData('text/plain')
if (file && !text) {
e.preventDefault()
+
+ const allowedFileTypes = fileConfig.allowed_file_types || []
+ const fileType = getSupportFileType(file.name, file.type, allowedFileTypes?.includes(SupportUploadFileTypes.custom))
+ const isFileTypeAllowed = allowedFileTypes.includes(fileType)
+
+ // Check if file type is in allowed list
+ if (!isFileTypeAllowed || !fileConfig.enabled) {
+ notify({
+ type: 'error',
+ message: t('common.fileUploader.fileExtensionNotSupport'),
+ })
+ return
+ }
+
handleLocalFileUpload(file)
}
- }, [handleLocalFileUpload])
+ }, [handleLocalFileUpload, fileConfig, notify, t])
const [isDragActive, setIsDragActive] = useState(false)
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {