Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error adding FileList to FormData #5511

Closed
FabioPaulino opened this issue Jan 31, 2023 · 0 comments · Fixed by #5518
Closed

Error adding FileList to FormData #5511

FabioPaulino opened this issue Jan 31, 2023 · 0 comments · Fixed by #5518

Comments

@FabioPaulino
Copy link

FabioPaulino commented Jan 31, 2023

Describe the bug

While the toFormData is ready to receive a FileList, the function tries to iterate it over a normal forEach which leads to a

TypeError: arr.forEach is not a function
    at FormData.defaultVisitor (toFormData.js:157:1)
    at each (toFormData.js:184:1)
    at Object.forEach (utils.js:256:1)
    at build (toFormData.js:183:1)
    at toFormData (toFormData.js:194:1)
    at Object.transformRequest (index.js:71:1)
    at transform (transformData.js:21:1)
    at Object.forEach (utils.js:247:1)
    at Object.transformData (transformData.js:20:1)
    at Axios.dispatchRequest (dispatchRequest.js:38:1)

image

To Reproduce

Add a file input to the form and try to submit:

const FormFileInput = (props: FormFileInputProps) => {
  const { control, name, multiple } = props;
  const { field } = useController({ control, name });
  const [value, setValue] = React.useState('');
  return (
    <input
      type="file"
      value={value}
      onChange={(e) => {
        setValue(e.target.value);
        field.onChange(e.target.files);
      }}
    />
  );
};

Error should appear both on a single or multiple file upload.

Code snippet

No response

Expected behavior

The FileList should be iterated:

Array.prototype.forEach.call(arr, function(file) { ... });

Axios Version

1.2.6

Adapter Version

No response

Browser

Edge

Browser Version

109.0.1518.61

Node.js Version

No response

OS

No response

Additional Library Versions

React 18.2.0
React-Hook-Form 7.40.0

Additional context/Screenshots

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant