0

I want to send and image AND other text information, I saw that for the image I need to use enctype="multipart/form-data" in the form. But doing this make me unable to see the other information needed.

 <form action="/new" enctype="multipart/form-data" method="post">
      <input type="text" id="name" value=""/>
      <input type="file" name="image" accept="image/*"  value="Compagny Logo"/>
      <input type="submit" value="Load compagny"/>
</form>

var storage = multer.diskStorage({
    destination: (req, file, callBack) => {
        callBack(null, './public/images/')
    },
    filename: (req, file, callBack) => {
        callBack(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname))
    }
})
 
var upload = multer({
    storage: storage
});

router.post("/new", upload.single('image'), (req, res) => {
        console.log(req.file.filename) // work
        console.log(req.name) // does'nt work
    }
});

Is there and other enctype I need to use ?

  • did you tried `req.body.name` – bill.gates May 09 '22 at 16:58
  • 1
    You can remove enctype, use this SO page to help you convert your image into a base64 string (https://stackoverflow.com/a/6150397/3155240), send both strings to your express server, and in your express / node code convert the base64 string to an image and write it to a file, which is how most people do it, I believe. – Shmack May 09 '22 at 17:09
  • nope Ifaruki it's 'undefined' and thank us @Shmack i'll do that – Jonathan Layduhur May 09 '22 at 17:17

0 Answers0