0

FilePond onupdatefiles method is called two times. pic As seen in the photo, two of the same file is selected. How can I prevent this?

React code

    <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)
                        }
                    };
                }
            }

            }
        />
meren
  • 432
  • 5
  • 19
  • It's called once for adding a new file and then again when that file has been loaded from the resource (has been turned in a file object), you can use the status property to determine the state of the file item. – Rik May 05 '20 at 08:01
  • @Rik how can i get the status of file? – meren May 05 '20 at 08:33
  • https://pqina.nl/filepond/docs/patterns/api/file/#properties – Rik May 11 '20 at 09:17

0 Answers0