I am using AngularJS on the frontend and NodeJS as backend. The code is working on my localhost, but while deploying it's not working throwing the following error:
code: "ENOENT"
errno: -2
path: "public/uploads/documentcontrol/part-1486706454112.pdf"
storageErrors: Array[0]
syscall: "open"
I am not sure what syscall or code means. Could you please help me when this error happens?
I have written the following code:
// Upload files
var storage = multer.diskStorage({ //multers disk storage settings
destination: function (req, file, cb) {
cb(null, './public/uploads/documentcontrol');
},
filename: function (req, file, cb) {
var datetimestamp = Date.now();
cb(null,'part' + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1]);
}
});
var upload = multer({ //multer settings
storage: storage
}).single('file');
router.post('/upload', function(req, res){
console.log("Body: ", req.file);
upload(req,res,function(err){
if(err){
res.json({error_code:1,err_desc:err});
return;
}
res.json({error_code:0,err_desc:null, output: req.file});
});
});
Does the folder public/uploads/documentcontrol/ exist? That could be it 馃
@LinusU Yes, the folder exists. Strangely, I resolved it. I've included the full path i.e. /home/__/__/public/uploads/documentcontrol
@samipjain Hi. I am having this issue too. Locally the code is working normally, but on my remote instance it just give me this error. Like you, my "uploads" folder exists; I changed the path to full path, the thing is, the error still exists. Could you please give me the exact path you used on your server side? Thanks in advance!
@JacobGarcia Hi, this is the exact line which I wrote : cb(null, __dirname.replace('routes', '') + 'public/uploads/foldername');
Most helpful comment
@JacobGarcia Hi, this is the exact line which I wrote : cb(null, __dirname.replace('routes', '') + 'public/uploads/foldername');