Reputation: 308
I want to upload image in a form using Express-Hnadlebars. here is my form (made it simpler, I have other text
types)
<form action="{{{postRoute}}}" method="POST" enctype="multipart/form-data">
<label class="btn btn-primary" style="width: 100%; margin: 0; cursor: pointer;">افزودن تصویر
<input name="image" onchange="readURL(this);" type="file" style="opacity: 0; position: absolute;">
</label>
<button type="submit" class="btn btn-primary" style="margin-top: 30px; width: 50%;">ایجاد
اعلان</button>
</form>
and In my express function , I log the req.body but its an empty object.
If I remove the enctype="multipart/form-data"
it works and req.body
has valus for my input with the texts and the file is just filename (which is useless .. isn't it?).
Upvotes: 0
Views: 1445
Reputation: 566
for uploading image using express you will need a middleware for handling multipart/form-data you can try this one : https://www.npmjs.com/package/multer
Upvotes: 1