Was using multiparty node module in node app for uploading a single file. Now, I want to upload multiple files using the same multiparty module.I googled but could not find any solution and ended up finding 'multer' module in the link which is giving some issue with the existing application. So, is there any way to achieve uploading of file using 'multiparty' ?
Asked
Active
Viewed 1,443 times
2 Answers
2
After many failed attempts and experimentation got the answer, have sent a form object to the server from the client. Just have a check of the below code on the 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 to 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 to :"+newPath);
});
});
}

Worker
- 283
- 1
- 9
- 20
-
I did the very same than you and did just upload only the last file. The only difference was that I did the readFile and fs.writeFile inside the For. I don't know why it wasn't working. Anywa thanx! :D @Worker – Despertaweb Oct 11 '16 at 18:35