首页 > 解决方案 > 如何在nodejs中存储req.body.state

问题描述

这是node js中服务器的后端部分

stub.PostWorkflowResults(
  
    {
        workflow_id: "Demographics",
        inputs: [
        {data: {//need req.body.input here //}}
    ]
},

    metadata,
    (err, response) => {
   if(response){
    console.log(response)
   }else {
       console.log(err)
   }

我使用了bodyparser。需要的是将 req.body.input 放入对象中{data: {//need req.body.input here //}}

标签: node.jsexpressbackendclarifai

解决方案


为什么不实现这样的代码?

app.post('/', function(req, res){
    stub.PostWorkflowResults(
    {
        workflow_id: "my-custom-workflow",
        inputs: [
            {
            data: {
                image: {
                    url: req.body.input // guessing that your input is a url
                }
            }
        }
    ]
    },
    metadata,
    (err, response) => {
    if (err) {
        throw new Error(err);
    }

    if (response.status.code !== 10000) {
        throw new Error("Post workflow results failed, status: " + response.status.description);
    }

    // Since we have one input, one output will exist here.
    const result = response.results[0]

    // One output is present for each model in the workflow.
    for (const output of result.outputs) {
        console.log("Predicted concepts for model: " + output.model.name);
        for (const concept of output.data.concepts) {
            console.log("\t" + concept.name + " " + concept.value);
        }
        console.log();
    }
}
);
});

推荐阅读