upload.js
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var request=require('request');
var fs=require('fs');
var domain = require('../../config/common.js').domain;
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));
// });
// }
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:"请求类型错误"});
}
}
}