I have a project in which I am using a basic sign up page for a user to enter their details. I am using express JS at the backend
In this, I am also asking them to upload a picture. But for the picture to be uploaded, I need to make the enctype of the form as multipart/form-data. The image gets uploaded, but the problem is that none of the other data is recorded.
This is the html:
<form action="/create" method="POST" class="profile" enctype="multipart/form-data">
<input type="file" name="profile_image" class="img_upload" /><br><br><br>
<div class="name_age" >
<input type="text" name="name" class="name" placeholder="Full name">
<b class="age"> Age </b>
<input type="date" name="age" class="age"/>
</div>
<input type="submit" name="submit" value="Update Profile" class="button"/>
</form>
And this is expressJS code for handling it:
app.post('/create',(req,res)=>{
var d = req.body
console.log(d)
upload(req,res,function(err){ //this is a multer function to store the image
if(err)
res.end(err)
else{
res.end('success')
}
})
})
The console.log(d) returns an empty object. Without multipart/form-data the image doesn't get uploaded,but the rest of the data gets recorded.
How do I solve this issue?