小编Aks*_*kar的帖子

如何从邮递员发送其中包含文件的对象数组

我想要邮递员以特定格式发出请求,但我不知道该怎么做。

因此,我想将数据从邮递员发送到对象数组中的本地 API。该对象包含文本信息,并且可能有一个文件,而我有多个这样的对象。例如:

[{
   id: 1,
   question: How are you ?,
   answer: I am fine.
},
{
  id : 2,
  question: "upload your document",
  answer: [file]
}
]
Run Code Online (Sandbox Code Playgroud)

这就是我的请求在邮递员上的样子,

在此输入图像描述

这就是我在后端获取它的方式

 { additonalQuestion:
   [ '12',
      'Upload your document',
      'file',
      '13',
      'How old are you ?',
      'text',
      '16' ] }
Run Code Online (Sandbox Code Playgroud)

我正在使用强大的节点包来阅读它。下面是代码

const formidable = require('formidable');

  const form = formidable({ multiples: true });
  await form.parse(req, (err, fields, files) => {
    console.log('fields: ', fields);
  });
Run Code Online (Sandbox Code Playgroud)

总结我的问题,我如何向邮递员提出请求,我可以在其中获得类似的请求

[{
   id: 1,
   question: How are you ?, …
Run Code Online (Sandbox Code Playgroud)

node.js express postman

5
推荐指数
0
解决办法
274
查看次数

标签 统计

express ×1

node.js ×1

postman ×1