am totally unable to upload image file through this code,
actually am trying to upload the img file and it'd save in particular dir like folder inside folder (Ex) UserUploads-> Customer1->img.jpg/png.
if i run following code it just shows img.jpg name and extension next to choose file, then if i click to submit means it doesn't works what i expect..!!
help will appreciate greatly.
thanks in advance guys...
(note: help me asap, have to submit my university project by next wk, else ll failed )
router.post('/photo',[ multer(
{
dest:'./uploads/',
rename: function (fieldname, filename, req, res) {
console.log(fieldname);
console.log("=============");
// console.log(req.body.can);
console.log("=============");
console.log(filename);
//return filename.replace(/\W+/g, '-').toLowerCase() + Date.now()
return filename
},
onFileUploadComplete: function (file, req, res) {
console.log(file.fieldname + ' uploaded to ' + file.path)
// res.json({"responseCode":1});
},
changeDest: function(dest, req, res) {
dest += '/uploads'+req.body.can;
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
return dest;
}
})
]);
router.post('/photo', function (req, res) {
id : req.body.can
//console.log(req.body.can)
//;return;
var form = {
body: req.body,
files: req.files
}
res.send(form);
});