0

My requirement is for every firewall, the user is going to upload a file. That i will be uploading in memory and save the filename to mongo db.

if there are 3 firewalls, only the last one is getting updated. remaining files are uploaded but location is not updated in DB. Below is my code:

fwid=await Firewall.find({fwno:id})
for(i=0;i<fwid.length;i++){
// I used this since fwid[i].id is showing error while uploading
req.session.updateid=fwid[i].id
  var y="b"+b; 
  var change=req.file(y);
 change.upload({maxBytes:1000000,dirname:'../../assets/images/logs'}, async function onUploadComplete(err, files1) {
     if (err) {
      message="error occured while uploading files.please try again";
      console.log(err);
      FlashService.error(req,message);
       res.view('pages/dashboard/home')
     }  
     else if(files1.length==0){
       console.log("no file uploaded")
      var fwids = await Firewall.update({id:req.session.updateid}).set({fwchangefilelocation:changelocation}).fetch()
      console.log(fwids)
     }
     else{
       console.log('file uploaded')
     var changelocation1=files1[0].fd.toString();var start=changelocation1.lastIndexOf('\\');
      changelocation1=changelocation1.substring(start+1);
        var gh = await Firewall.update({id:req.session.updateid}).set({fwchangefilelocation:changelocation1}).fetch()
     
      }
  });
  b++;
}

My sails version is: 1.2.3 node version: 12.16

Can someone help me please?

Surendar
  • 153
  • 3
  • 11

0 Answers0