pqina / react-filepond

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

Name passing as empty object using an instance. #90

Closed mazer-rakham closed 5 years ago

mazer-rakham commented 5 years ago

Hello, Using refs on FilePond instances creates an empty name object on the input. In my component:

 submitImages = (fieldName) => {
    const formData = new FormData();  
    this.pond.getFiles()
      .map(fileItem => fileItem.file)
      .forEach(file => {   
        formData.append(fieldName, file, file.name);        
      });
      console.log(formData);
     this.props.addUserPhoto(formData);

  }

// stuff here
 <Form onSubmit={this.submitImages}>
    <Form.Field>
        <FilePond ref={ref => this.pond = ref} name="userphoto" />
     </Form.Field>
      <Form.Field>
        <Button type="submit">submit</Button>
      </Form.Field>
</Form>

Sends an name="[object Object]" in the Form Data request and the backend, attached screenshot. image

rikschennink commented 5 years ago

You're referencing submitImages in your onSubmit callback, fieldName will be an event object, and you're using it as the field name in the formData object, therefor it's an [object Object].

The issue is not related to FilePond.