pqina / react-filepond

🔌 A handy FilePond adapter component for React
https://pqina.nl/filepond
MIT License
1.85k stars 90 forks source link

adding user supplied values to payload #12

Closed indefinitelee closed 6 years ago

indefinitelee commented 6 years ago

How can I add some user supplied values along with the file payload sent to my server? for example, my users will need to add a file and then input some values such as

{
  client: "Acme Inc.", 
  clientId: 123, 
}

i can easily add some input fields and clickHandlers to get those values into state, but not sure how to get FilePond to access them and send to backend.

thanks

rikschennink commented 6 years ago

You can add metadata to files using the setMetadata method or you can add the metadata to the request right before upload in a custom processing method.

indefinitelee commented 6 years ago

so using the metadata plugin i'd do something like:

FilePond.setOptions({
    fileMetadataObject: {
       userId: this.state.userId,
       customName: this.state.customName
    }
})

and these will be included on the file data sent to my server?

rikschennink commented 6 years ago

I think that will take the initial state value and copy it to files, if the state updates the metadata will not.

I think calling setMetadata on each file after the state updates would be better if you want the latest value.

LeviStrange commented 5 years ago

Hi, I am struggling to add user form data to a file upload. How can I do this?

rikschennink commented 5 years ago

@LeviStrange please don't double post. https://github.com/pqina/react-filepond/issues/36