node.js - Sending files between HTTP endpoints nodejs -


working on file transfer utility , having mess of time getting transfers done correctly.

i have folder watching done chokidar, , on add in chokidar, create file object added array. each object looks this:

l.files.push({   dateadded: date.now(),   filename: filename,   filepath: filepath,   fullpath: p   }); 

and client checks in, get's number of files available download, makes http request each of files:(enclosed in object)

getfile: (loc, home) => {   var connection = home + 'files/?loc=' + loc;   h.get(connection, (res) =>{     let filepath = config.thisincoming;     console.dir(res.body);    });    } 

home baseurl api call, loc location identifier api find.

the express endpoint setup respond call this:

app.get('/files', (req, res) => {   // console.dir(req);   for( let f of filepaths){     console.dir(f);     if((f.name === req.query.loc)&&(f.files.length > 0)){       let file = f.files.pop();       var filename = file.filename;       fs.readfile(file.fullpath, (err, dat) => {         if(err){           console.log(err);           res.send({status: 'no files'});         }else{          if(dat){             console.log(dat);             res.send({name: filename, data: dat});           }         }       });       }     } }); 

i didn't want go res.download() or res.sendfile() methods wanted able send file name along data in file. i've set send buffer, on client side, logs undefined console should log buffer data.

is there better way this? there library can this? proper/better way this?


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -