javascript - Is it possible to upload multiple files using module "multiparty" in node? -
was using multiparty node module in node app uploading single file. now, want upload multiple files using same multiparty module.i googled not find solution , ended finding 'multer' module in link giving issue existing application. so, there way achieve uploading of file using 'multiparty' ?
after many failed attempts , experimentation got answer, have sent form object server client. have check of below code on server side
app.post('/multifileupload', function(req, res) { var singlefile; var form = new multiparty.form(); form.parse(req, function(err, fields, files){ var filearry=files.uploadfiles; if(filearry == null ){ res.send('no files found upload.'); return; } for(i=0; i<filearry.length; i++) { newpath='./uploads/'; singlefile=filearry[i]; newpath+=singlefile.originalfilename; readandwritefile(singlefile,newpath); } res.send("file uploaded to: " + newpath); }); }); function readandwritefile(singlefile , newpath){ fs.readfile(singlefile.path, (err, data)=>{ fs.writefile(newpath, data, (err)=>{ console.log("file uploaded :"+newpath); }); }); }
Comments
Post a Comment