0
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.

  • critically missing information: on which line is that error getting thrown? (also you have one comma too many after your form's `version`. Good idea to always make sure your code passes [linting](https://www.npmjs.com/package/jshint), so you can rule out syntax errors) – Mike 'Pomax' Kamermans Jul 22 '15 at 05:08
  • edited the code.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. – Vijay Malik Jul 22 '15 at 05:36
  • it looks like you can throw away a lot of code that is not currently contributing to your problem, then, to come up with a true [minimal error-reproducing case](http://stackoverflow.com/help/mcve) (getting to that is often a great exercise because you almost always end up finding exactly where things going wrong while reducing). If `req.body.widgetReleaseId` is undefined, then that's the real problem: where is that supposed to come from, and why is your code not testing it exists before even POSTing to the accepting server? – Mike 'Pomax' Kamermans Jul 23 '15 at 16:14

0 Answers0