[英]react-dropzone accepts all uploaded file types instead of specified file type(s) in "accept" parameter
當我上傳文件時,我的react-dropzone
'accept': { .. }
參數似乎完全被忽略了。
我的useDropzone({})
:
const {getRootProps, getInputProps, isDragActive} = useDropzone({
onDrop,
noClick: true,
'accept': {
'video/mp4': ['.mp4', '.MP4'],
},
})
我的onDrop
回調:
const onDrop = useCallback((acceptedFiles, rejectedFiles) => {
let test = acceptedFiles.length || rejectedFiles.length
? `Accepted ${acceptedFiles.length}, rejected ${rejectedFiles.length} files`
: "Try dropping some files.";
console.log(test);
if (acceptedFiles.length > 0) {
setSelectedFiles(acceptedFiles);
}
acceptedFiles.forEach((file, index, array) => {
const reader = new FileReader()
reader.onabort = (event) => {
console.log('file reading was aborted')
}
reader.onerror = (event) => {
console.log('file reading has failed')
}
reader.onload = (event) => {
// Do whatever you want with the file contents
const binaryStr = reader.result
console.log(binaryStr)
}
reader.readAsArrayBuffer(file)
})
}, [])
編碼:
let test = acceptedFiles.length || rejectedFiles.length
? `Accepted ${acceptedFiles.length}, rejected ${rejectedFiles.length} files`
: "Try dropping some files.";
總是返回: Accepted 1, rejected 0 files
無論如何,即使我上傳了pdf
、 jpg
、 txt
等, rejected
也總是0
這是代碼框鏈接:https ://codesandbox.io/s/kind-frost-zmyhd8?file=/pages/index.js
有人知道我的代碼有什么問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.