Expressjs-如何将值从一种方法传递给另一种方法

时间:2016-06-24 04:30:21

标签: mongodb express mongoose angular

我有一个休息后api,它从angular2获取文件并将其上传到AWS。

它调用上传方法在AWS上存储文件。文件对象具有位置url,我想将其传递回调用方法以将其存储在MongoDB中。

app.post('/s3upload', upload.array('uploads[]',12), function (req, res, next) {
         var filemongo = new FileMongo();
         filemongo.originalname = req.files[0].originalname;
         filemongo._idapt = req.body._idapt;
         filemongo.createddate = Date.now();
    //     console.log(filelocation);         
         filemongo.save(function(err) {
        });
    (res.send(req.files)); 
});

上传就像这样调用

var upload = multer({
    storage: multers3({
        s3:s3,       
        bucket: 'angular2files',
        key: function (req,file, cb) {
              cb(null, file.originalname); 
  //          filelocation = file.location;    ----> how can I pass this location back to the calling method 
        }
    })
});

0 个答案:

没有答案