首页 > 解决方案 > 从一个 Nodejs 函数向另一个函数发送 Post Data “mutlipart”

问题描述

我想将在下面的 post 方法中收到的相同数据发送到另一个 app.post 方法。

app.post('/sign_up', (req, res) => {
    var name = req.body.fullname,
    email = req.body.email,
    password = req.body.password,
    cpassword = req.body.cpassword;

    var base64Str = req.body.image;

    var obj = { name: name, email: email, password: password, cpassword: cpassword, b:base64Str };
    console.log("Server Recieved: ");
    console.log(obj);

    //Now here want to submit this data as post to another 
    //app.post("/get_data", function(req, res)) { //do something else   } )

});

让我知道如何实现这一目标?

标签: javascriptnode.jsexpressmultipartform-datanode-modules

解决方案


您可以为“/get_data”路由使用命名函数,并在“/sign_up”路由的末尾调用该函数。

请参阅下面的示例代码。

app.post('/sign_up', (req, res) => {
  var name = req.body.fullname,
    email = req.body.email,
    password = req.body.password,
    cpassword = req.body.cpassword;

  var base64Str = req.body.image;

  var obj = {
    name: name,
    email: email,
    password: password,
    cpassword: cpassword,
    b: base64Str
  };
  console.log("Server Recieved: ");
  console.log(obj);

  //Now here want to submit this data as post to another 
  get_data(req, res);

});

app.post("/get_data", get_data);

const get_data = function(req, res)) {
  //do something else
};


推荐阅读