|
|
var request=require('request');
|
|
|
var fs=require('fs');
|
|
|
var domain = require('../../config/common.js').domain;
|
|
|
//var domain = require('../../config/common.js').domain;
|
|
|
//var domain = 'http://172.16.6.227:8083/yohobuy-platform-web';
|
|
|
//var domain = 'http://192.168.102.202:8088/platform';
|
|
|
//var domain = 'http://172.16.6.240:8088/platform';
|
|
|
var domain = 'http://172.16.6.240:8088/platform';
|
|
|
var env = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
exports.uploadFile=function(req,res){
|
|
|
|
|
|
// TODO 代理上传
|
|
|
// 方法1
|
|
|
if(env==="development"){
|
|
|
res.json({
|
|
|
"code":200,
|
|
|
"data" : "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
|
|
|
"message":"success"
|
|
|
});
|
|
|
}else{
|
|
|
if(req.is("multipart/form-data")){
|
|
|
req.body.file=fs.createReadStream(req.files[req.body.filename].path);
|
|
|
if(req.body.__type=="batch-import"){
|
|
|
request.post({url:domain+'/batch/import',formData:req.body},function optionalCallback(err, httpResponse, body){
|
|
|
res.json(JSON.parse(body));
|
|
|
});
|
|
|
}else{
|
|
|
request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
|
|
|
res.json(JSON.parse(body));
|
|
|
});
|
|
|
}
|
|
|
if(req.is("multipart/form-data")){
|
|
|
req.body.file=fs.createReadStream(req.files[req.body.filename].path);
|
|
|
if(req.body.__type=="batch-import"){
|
|
|
request.post({url:domain+'/batch/import',formData:req.body},function optionalCallback(err, httpResponse, body){
|
|
|
res.json(JSON.parse(body));
|
|
|
});
|
|
|
}else{
|
|
|
res.json({code:"500",message:"请求类型错误"});
|
|
|
request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
|
|
|
res.json(JSON.parse(body));
|
|
|
});
|
|
|
}
|
|
|
}else{
|
|
|
res.json({code:"500",message:"请求类型错误"});
|
|
|
}
|
|
|
//
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|