Handling multer with array of objects

Viewed 65

This question has been asked many times here I guess but there weren't any answers on this one. My case is that I have 2 array of objects in my API call and both of them has file uploads. The way multer works right now is doesn't look much decent. It creates an entire array of uploaded files with req.files. I know there is a helper function .fields() available but it will just divide the files based on main key and again it's going to be an array and that becomes hard to guess which file goes to which object. I had a temporary solution to pass the file name in each object with file so that we can filter it out but I don't feel it valid.


const uploadObject = {
first: [
  {
    name: "something",
    file: (FileObject)
  },
  {
    name: "something else",
    file: (FileObject)
  },
],
second: [
  {
    name: "something",
    file: (FileObject)
  },
  {
    name: "something else",
    file: (FileObject)
  },
]
}

Isn't there any way with muter where we can atleast move the files within body(not inside req.files)? Also If anyone have any different library suggestion for cases like these?

0 Answers
Related