我想阅读图片并将其附加到请求正文,如下所示:
// 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)
});
});
只有一个请求和一个表单元素。
答案 0 :(得分:0)
您应该可以使用Array.prototype.forEach()
forms.forEach(form =>
request.post( { url : url, formData: form }
, (err, response) => console.log(response.body))
);