अपने ऐप में multerhelper.js फ़ाइल बनाएं और उसमें नीचे कोड जोड़ें
const multer = require('multer');
// const fs = require('fs');
let fs = require('fs-extra');
let storage = multer.diskStorage({
destination: function (req, file, cb) {
let Id = req.body.id;
let path = `tmp/daily_gasoline_report/${Id}`;
fs.mkdirsSync(path);
cb(null, path);
},
filename: function (req, file, cb) {
// console.log(file);
let extArray = file.mimetype.split("/");
let extension = extArray[extArray.length - 1];
cb(null, file.fieldname + '-' + Date.now() + "." + extension);
}
})
var upload = multer({ storage: storage });
let createUserImage = upload.single('images');
let multerHelper = {
createUserImage,
}
module.exports = multerHelper;
अपनी user.js फ़ाइल में इस फ़ाइल को आयात करें
const multerhelper = require("../multerhelper.js");
router.post('/register',multerhelper , function(req,res,next){