Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);
});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900