var form = {
widgetReleaseId: req.body.widgetReleaseId,
version: req.body.version,
uploadDate: req.body.uploadDate,
myfiles : myfiles
};
Below is npm request.
request.post(
{
url:target_url+'widget-releases/',
formData:form
}, function optionalCallback(err, httpResponse, body) {
console.log('body'+body)
if (err) {
console.log(err)
}
del(['uploads/'+req.session.loginuser+'**/*'], function (err, paths) {
console.log('Deleted files/folders:\n', paths.join('\n'));
});
res.redirect('/admin-ui/widget-release/add');
});
Api exposed 'Post' on another nodejs Server. .Error is coming while reading the files from folder which supposed to be created using multer. Since req.body.widgetReleaseId is 'undefined' ,it is not creating the folder to copy the files
router.post('/',multer({
dest: './public/api/downloads/',
changeDest: function(dest, req, res) {
dest += req.body.widgetReleaseId;
var stat = null;
try {
stat = fs.statSync(dest);
} catch (err) {
mkdirp.sync(dest);
}
if (stat && !stat.isDirectory()) {
throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');
}
return dest;
},
rename: function(fieldname, filename, req,res){
return filename.replace(/\W+/g, '-');
},
onFileUploadStart: function (file, req, res) {
console.log(file.fieldname + ' is starting ...')
},
onFileUploadComplete: function (file, req, res) {
console.log(file.fieldname + ' uploaded to ' + file.path)
} ,
onError: function (error, next) {
console.log(error)
next(error)
}
}), function(req,res) {
//code goes here..
fs.readdir('./public/api/downloads/'+req.body.widgetReleaseId,function(err,files ){
....
});
Body-parser settings are correct and before any routing. It was working few days back but now getting Error: ENOENT error as there is no data coming in with formData to nodejs server. Any Clue? I had cleaned the cache and update the project as well.