如何使选定的文件类型仅接受docx
?我希望所选文件docx
仅具有扩展名。我应该采用哪种过滤?我怎样才能做到这一点?
React 代码示例
return (
<>
<Form className='orange-color ml-2'>
<FilePond
ref={ref => (ref)}
allowFileEncode={true}
allowMultiple={false}
oninit={() =>
console.log("FilePond "+formKey.toString()+" has initialised")
}
onupdatefiles={(fileItems) => {
const file = fileItems.map(fileItem => fileItem.file)
if (file[0]) {
const reader = new FileReader();
reader.readAsDataURL(file[0]);
reader.onload = (event) => {
const convertedResult = event.target.result
if (convertedResult) {
const regex = '(.*)(base64,)(.*)';
const matches = convertedResult.match(regex);
const val = matches[3];
changeSelected(val)
}
};
}
}
}
/>
<Form.Check>
<Form.Check.Input required
checked={input.value !== null}
style={{display:'none' }}
/>
<Form.Control.Feedback type="invalid" >Required</Form.Control.Feedback>
</Form.Check>
</Form>
</>
)
文件类型验证插件可处理对错误类型文件的阻止。当基于输入类型文件创建FilePond实例时,此插件将自动解释accept属性值。
我不明白如何添加我想要的文件扩展名
我以前没有使用过FilePond,但是从文档看来,它只是读取标准输入accept属性。因此,应该只需要
acceptedFileTypes: ['.docx'],
查看它即可:pqina.nl/filepond/docs/patterns/plugins/file-validate-type / ...当前不支持@Mystik通过扩展开发的验证。参见github.com/pqina/filepond-plugin-file-validate-type/issues/4了解如何根据mimetype进行验证。