const fs = require('fs')
const request = require('request');
let files = ctx.request.files
let body = ctx.request.body
//循环遍历文件
Object.keys(files).forEach((key) => {
abc[key]={
value: fs.readFileSync(files[key].path), //读取上传的文件->文件流
options: {
filename: files[key].name,
contentType: files[key].type
}
}
})
//循环遍历参数
Object.keys(body).forEach((key) => {
abc[key]=body[key]
})
return new Promise((resolve, reject) => {
request.post({
headers:{
'x-auth-token':forward_token
},
url:api,
formData:abc
}, function optionalCallback(err, httpResponse, body) {
if (err) {
console.log(err)
reject(err)
}
resolve(JSON.parse(body))
});
})