javascript - Node.js post multiple files to server -
i working on small node.js script upload multiple files api via form data.
my current code looks like:
request.post(config.starturl, function (err, res, processbody) { var commit = function() { console.log("commit process"); } var fetch = function(file,cb){ var addreq = request.post(addurl, function(err,response,filebody){ if ( err){ cb(err); } else { var addform = addreq.form(); addform.append('filename', file); addform.append('filedata', fs.readfilesync(file)); cb(null, filebody); // first param indicates error, null=> no error } }); } async.map(files, fetch, function(err, results){ if (err){ console.log("error",err); } else { console.log("all files uploaded.",results); commit(); } }); });
i try handle array filepaths. should uploaded given addurl using request plugin.
the commit() function called when files loop finished, files not transferred server correctly.
thanks help!
Comments
Post a Comment