mirror of
https://github.com/langgenius/dify.git
synced 2026-01-08 07:14:14 +00:00
Add file type validation to paste upload (#28017)
This commit is contained in:
@@ -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>) => {
|
||||
|
||||
Reference in New Issue
Block a user