node.js - Create new Folder with Formidable -


i have next code:

router.post('/subirarchivo', function (req, res){ var form = new formidable.incomingform();  form.parse(req);  form.on('filebegin', function (name, file){     file.path = path.join(__dirname,'../../../../uploads/', file.name);  });  form.on('file', function (name, file){     console.log('uploaded ' + file.name); });  res.sendfile(path.join(__dirname,'../../../client/views/fasevinculacion', 'busquedavinculacion.html')) 

upload file it's fine, but, how create new folder not exists?

first need add fs-extra (easier way)
, in post, add:

fs.mkdirssync(__dirname + '/../public/dist'); form.uploaddir = __dirname + '/../public/dist'; 

more details:

if (req.url == '/upload') {     var form = new formidable.incomingform(),         files = [],         fields = [];      fs.mkdirssync(__dirname + '/../public/dist');     form.uploaddir = __dirname + '/../public/dist';       form       .on('field', function(field, value) {         console.log(field, value);         fields.push([field, value]);       })       .on('file', function(field, file) {         console.log(field, file);         files.push([field, file]);       })       .on('end', function() {         console.log('-> upload done');         res.writehead(200, {'content-type': 'text/plain'});         res.write('received fields:\n\n '+util.inspect(fields));         res.write('\n\n');         res.end('received files:\n\n '+util.inspect(files));       });     form.parse(req);   } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -