0

I am not able to send multipleimages to node server, I have sent single image but not multiple

  const {register,handleSubmit}=useForm() 

    const onSubmit = async(images) => {
        const imageArray= Object.keys(images).map(item =>{ 
            return images[item] 
        })        

         let formData = new FormData()

        imageArray.map((file, index) => {
            formData.append(`images`, file[index])
          })   
       await uploadMultipleImages(formData)
    }
    return (
        <>
            <form onSubmit={handleSubmit(onSubmit)}>
                <input type='file' multiple {...register('multipleImages')} />
                <button type='submit' >Upload multiple images</button>
            </form>
        </>
    )
ASIF KAIF
  • 317
  • 1
  • 4
  • 17
  • Does this answer your question? [Uploading multiple files using formData()](https://stackoverflow.com/questions/12989442/uploading-multiple-files-using-formdata) – Omri Attiya Aug 28 '21 at 04:56

1 Answers1

0

It's a possible duplicate of this thread.

According to this and according to MDN, you should add [] to your name if you want to append multiple files on the same name.

So just:

...
formData.append(`images[]`, file[index])
...
Omri Attiya
  • 3,917
  • 3
  • 19
  • 35