I have a submit form in my React project, where I'm using the filepond API, so users can submit files to the form
I'm just using the standard FilePond component taken from the documentation so far.
<FilePond ref={ref => this.pond = ref}
allowMultiple={true}
maxFiles={4}
oninit={() => this.handleInit() }
onupdatefiles={(fileItems) => {
// Set current file objects to this.state
this.setState({
files: fileItems.map(fileItem => fileItem.file)
});
}}>
{/* Update current files */}
{this.state.files.map(file => (
<File key={file} src={file} origin="local"
/>
))}
</FilePond>
I'm sending the entire request to a backend REST server in java, and therefore I want to send along to types of information, the data (base64 encoded), and the extension of the file.
I do this by creating an array of objects in my request
result: this.state.files.map(file => ({
"file": this.findFileTypeHandler(file.name),
"data": this.encodeFileHandler(file)
}))
}
in my encodeFileHandler, I need a way to convert the data to base64, but I can't see a property, that has the raw data, on the file object.
Is there a way to access it, or does anybody have a better alternative I could use?