gpt4 book ai didi

javascript - 如何使用 FilePond 使所选文件类型仅接受 docx?

转载 作者:行者123 更新时间:2023-12-03 14:22:06 26 4
gpt4 key购买 nike

如何才能使所选文件类型仅接受 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>
</>
)

最佳答案

The File Type Validation plugin handles blocking of files that are of the wrong type. When creating a FilePond instance based on a input type file, this plugin will automatically interpret the accept attribute value.

https://github.com/pqina/filepond-plugin-file-validate-type

关于javascript - 如何使用 FilePond 使所选文件类型仅接受 docx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61595517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com