Multer is not uploading files on server directory below my source code to upload file. file object is created that means when i log req.files file are present but not uploading to directory.im using POSTMAN for API Testing sending file through formdata->uploadfiles and with key "uploadfiles" destinition function is not called because log inside function is not console the name "Hello "
const storage = multer.diskStorage({
destination: function (req, file, cb) {
console.log("Hello Umesh");
cb(null, '../resources/uploads'); // Absolute path. Folder must exist, will not be created for you.
},
filename: function (req, file, cb) {
console.log("Hello Umesh");
cb(null, file.fieldname + '-' + Date.now());
}
});
const upload = multer({
storage: storage,
limit:{filesize:10}
}).single('uploadfiles');
router.post('/save', function (req, res) {
upload(req, res, function (err) {
if (err) {
res.json({
success: false,
message:err
});
}
else{
res.json({
success: true,
message: req.file
});
}
})
});
../resources/uploads
exists? (Maybe you want to use __dirname instead of ../ to make sure it's the correct path – djaaxuploads
exist inside theresources
folder? – djaax