简体   繁体   中英

How to set title of uploaded image from another form value from Frontend in nodejs using multer?

I'm Developing an Application where I want to upload images to nodejs server using multer library. I want to entitle my file as "Id_Card_No" value received from Frontend in the same form as receiving the image. And store image's path in MongoDB. For example: Received value from Frontend: id_card_no: 1111-2222222-3 ID Card Image title: Abc.jpg

So I want to replace the title as "1111-2222222-3_IdCard.jpg"

Anyone please help me with the logic to do this??? Currently images are seccessfully being stored in server. I just need help with concatenating the path variable and title. Thanks in advance!

const storage = multer.diskStorage({
    destination: function(req, file, cb) {
        cb(null, 'uploads/');
    },
  
    filename: function(req, file, cb) {
        cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
    }
});
  
var upload = multer({ storage: storage })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM