How can I make the selected file type acceptable only as docx
?
I want the selected file to have a docx
extension only. What kind of filtering should I apply? How can I do that?
React code sample
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.