为什么这种形式与流阅读器的附件不能真正起作用?

时间:2016-07-30 15:30:00

标签: javascript node.js

我想阅读图片并将其附加到请求正文,如下所示:

// Sending files to server by adding and posting theme

// 1. loop through an array of file path pair ['file', 'path' ]

// 2. pass result to request function an post it

一些代码如下:

forms = [];
len = 3;
while (len > 0){
  forms.push({ 'fileName': fs.createReadStream (path) })
  len--
  }
async.each(forms, function(form) {
  request.post( { url : url, formData: form }, function(err, response) {
               console.log(response.body)
  });
});

只有一个请求和一个表单元素。

1 个答案:

答案 0 :(得分:0)

您应该可以使用Array.prototype.forEach()

forms.forEach(form => 
  request.post( { url : url, formData: form }
  , (err, response) => console.log(response.body))
);