Authored by 周奇琪

灰度中间件加files的处理

... ... @@ -6,6 +6,7 @@ var request = require('request');
var config = require('../config/gray');
var _ = require('lodash');
var fs = require('fs');
/**
* 灰度界面配置
... ... @@ -54,7 +55,11 @@ module.exports = function(proxyRoute) {
} else {
options.headers['cookie'] = req.session.gray;
}
//如果是上传文件添加文件信息到form表单
if(req.files && _.keys(req.files).length>0) {
options.formData = addFiles(req);
delete options.form;
}
logger.log('info','grayroute: request options: %j',options,{});
//发起代理请求
... ... @@ -89,3 +94,16 @@ module.exports = function(proxyRoute) {
}
}
}
/**
* 添加文件到body中
* @param {Object} req 请求对象
*/
function addFiles(req) {
var body = {};
_.forEach(req.files,function(v,k){
body[k] = fs.createReadStream(v.path);
});
_.merge(body,req.body);
return body;
}
\ No newline at end of file
... ...