0

So i am handling a multiple file upload on my client side, where my html looks like the following

form(method='post', enctype='multipart/form-data')#createReportForm
  input(type='file', multiple='multiple', accept='image/png, image/gif, image/jpeg, image/jpg', name='uploadImages', data-max-size='5000000')#uploadFile

Now on my server side to access the contents of the file and other info i am using req.files.uploadImages. This works fine if one file attached, but when multiple files are attached on the client this object only reads the last attached file and not the first one

Whats the reasoning behind this? Shouldn't req.files.uploadImages have info about both the files?

Raj
  • 337
  • 3
  • 6
  • 15

1 Answers1

0

If multiple files are selected the req.files.uploadImages would hold all the files.

You can just loop over them:

var files = [].concat(req.files.uploadImages);
for(var x = 0; x < files.length; x++){
   // upload file
}
mrvautin
  • 190
  • 1
  • 10