Is there a way to send both a file and a JSON object containing data using multer? I came across this thread, but it only explains how to attach one field at a time.
Here's what I currently have on the client side:
request
.post(uploadPOSTUrl)
.set('Accept', 'application/json')
.field('Test', object.TestField)
.attach('file', file)
.end((err, res) => {
if (err) {
} else {
}
});
and on the server side
export function upload(req, res){
console.log("UploadedJSON: ", req.body);
console.log("UploadedFile: ",req.file);
res.status(204).end();
}
However, instead of just sending one field, I need to send the entire object .field('Test', object)
. When I try this, I receive [Object object]
on the server side and can't access the fields.
At the moment, my only solution would be to loop through and add .field()
for every field in my object...