I am using FilePond (React) in order to upload files. I want only pdf files. I've installed the File Type Validation plugin with npm command : npm i filepond-plugin-file-validate-type --save and then npm run-script build command. I've tested and it's uploading all kinds of files.
This is my code :
import {registerPlugin} from 'react-filepond'
// Import the plugin code
import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type';
// Register the plugin
registerPlugin(FilePondPluginFileValidateType);
<FilePond
accepted-file-types={"application/pdf"}
server={{
process: async (fieldName, file, metadata, load, error, progress, abort) => {
await processFile(fieldName, file, metadata, load, error, progress, abort, setFileName);
}
}}
//server={{process: Config.pdfServer}}
//ref={ref => this.pond=ref} // To call instance methods
oninit={() => handleInit()}
// nom du fichier c'est file.name
// callback onupdatefiles- a file has been added or removed, receives a list of file items
onupdatefiles={(fileItems) => {
// Set current file objects to this.state
// boucler sur un tableau
setFile(fileItems.map(fileItem => fileItem.file));
// console.log(fileItem.getFileEncodeBase64String());
}}
allowFileEncode={true}
allowMultiple={false}
instantUpload={true}
onprocessfile={(error, file) => {
console.log('PROCESSED', file, 'SERVER_ID', file.serverId);
// console.log('ERROR PROCESSED', error);
}}
// callback tiré de la documentation FilePond - if no error, file has been succesfully loaded
onaddfile={(error, file) => {
console.log('PROCESSED', file, 'SERVER_ID', file.serverId);
// console.log('ERROR PROCESSED', error);
}}
/>
Thank you very much.
Edit: with accepted-file-types={['application/pdf']} it's not working ...