Rahadur
Rahadur

Reputation: 129

How to upload file using Multer from child object

I have a User object in my application, where each user Object has a Nominee as a child object With a File field name photo.

JSON Object

{
   name: 'Jhon Doe',
   phone: '01548761645',
   email: '[email protected]',
   photo: File(),
   nominee: {
     name: 'Nominee name',
     phone: '9876546542',
     photo: File()
   }
}

In Express

app.post(upload.fields([{name:'photo'}, {name:'nominee'}]), function(req, res) {

    res.send(req.files['photo']);        // send file details

    res.send(req.files['nominee']);     // did not show any file details
}

OR

app.post(upload.fields([{name:'photo'}, {name:'nominee.photo'}]), function(req, res) {

    res.send(req.files['photo']);             // send file details

    res.send(req.files['nominee.photo']);     // did not show any file details
}

In my express code i can access all file details for Parent Object but it did not show any details for child(nominee) Object. Is there anything wrong in my code or multer did not support nested child field..?

Upvotes: 3

Views: 1219

Answers (1)

luca petri
luca petri

Reputation: 41

I know it's a bit late but

upload.single('nominee[photo]')

Should do the job

Upvotes: 4

Related Questions