Monday 23 September 2019

Using MEVN stack, got a specific question about image upload with Multer. PLZ...

I have a rather specific question about Multer. I'm using the MEVN stack and managed to upload images to my server with Multer using a specific model with just one field for the image that looks like this:const image = new Image({file: req.file.path,});That worked fine. Before sending the image from my frontend, I converted it to a FormData object. So I did this:await axios.post(urlImage, formData);All good, easy peasy. However, I am trying to save an image in the following way with a 'person' model:const person = new Person({personData: {image: req.body.personData.file.path,basicInformation: req.body.personData.basicInformation,profile: req.body.personData.profile,experience: req.body.personData.experience,education: req.body.personData.education,skills: req.body.personData.skills,hobbies: req.body.personData.hobbies}});On the frontend with Vuejs I'm sending a Person object, that contains an image field that holds the formData and the rest of the fields are arrays of objects. Normally with Multer, the image is accessible with req.file.path as I did in the first example*.* But as you can see the FormData objects lives in req.body in the Person object*,* effectively making it (as far as I know) undefined with Multer. Whatever I try, the 'req.file'  is always undefined because of it. Is there no possible way to achieve this with Multer? I've got multiple posts on stackoverflow with zero answers. Am I stupid or something?

Submitted September 23, 2019 at 04:52PM by Mertakus

No comments:

Post a Comment