'Sending image and additional info via HTTP

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 ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source