[英]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.我正在开发一个应用程序,我想在其中使用 multer 库将图像上传到 nodejs 服务器。 I want to entitle my file as "Id_Card_No" value received from Frontend in the same form as receiving the image.
我想以与接收图像相同的形式将我的文件命名为从前端收到的“Id_Card_No”值。 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
并将图像的路径存储在MongoDB。例如:从前端接收的值: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"所以我想将标题替换为“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 })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.