简体   繁体   English

如何使用 multer 在 nodejs 中从前端的另一个表单值设置上传图像的标题?

[英]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.

相关问题 如何在nodejs中将上传的图像从multer保存到mongodb - How to save uploaded image from multer to mongodb in nodejs 使用 Multer,如何在用户上传另一张图像后从存储中删除先前的图像文件? - Using Multer, how do I delete the previous image file from storage after a user uploaded another image? NodeJS:-如何使用multer在mongo DB中存储表单中的图像并将相同的图像作为附件发送到邮件 - NodeJS:-How to store image from a form in mongo DB using multer and send the same image to mail as an attachment 使用 Nodejs Zlib 压缩从 Multer 上传的文件 - Compressing File Uploaded From Multer using Nodejs Zlib 使用 multer 从 nodejs 更新图像 - update image from nodejs using multer 使用 Multer 提交表单时如何防止图像保存 - How to Prevent an Image from Saving When Submitting Form Using Multer 如何使用 multer 从表单中获取上传文件的路径 - how do I get the path of the uploaded file from a form with multer 如何使用MULTER,Nodejs和MySQL发布表单数据(图像和数据) - How to post form data ( image and data ) using MULTER, Nodejs and MySQL Nodejs - 如何保存从前端发送到公共文件夹的文件 object 而不使用像 multer 这样的中间件? - Nodejs - how can I save a file object sent from frontend to the public folder without using middleware like multer? 如何使用multer显示上传的图像? - How to display uploaded image using multer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM