Authored by weiqingting

图片上传

@@ -54,9 +54,6 @@ module.exports=function(app) { @@ -54,9 +54,6 @@ module.exports=function(app) {
54 app.post("/productColor/queryProductColors","basegoods_queryProductColors"); 54 app.post("/productColor/queryProductColors","basegoods_queryProductColors");
55 55
56 /*获取(非)销售属性*/ 56 /*获取(非)销售属性*/
57 - app.post("/standard/queryAllBySortId4Html","basegoods_queryAllProductAttr");  
58 -  
59 - app.post("/product/queryMaterialList","basegoods_queryMaterialList");  
60 57
61 app.post("/product/querySortBySmallSort","basegoods_querySortBySmallSort"); 58 app.post("/product/querySortBySmallSort","basegoods_querySortBySmallSort");
62 59
@@ -130,20 +130,31 @@ module.exports={ @@ -130,20 +130,31 @@ module.exports={
130 result={code: "501",message: "用户失效,请重新登录"}; 130 result={code: "501",message: "用户失效,请重新登录"};
131 return callback(null, result); 131 return callback(null, result);
132 } 132 }
133 - req.body.file = fs.createReadStream(req.files.upfile.path); 133 + req.body.files = [fs.createReadStream(req.files.upfile.path)];
134 req.body.bucket="goodsimg"; 134 req.body.bucket="goodsimg";
135 request.post({ 135 request.post({
136 - url: config.domain + '/fileupload/upload',  
137 - formData: req.body  
138 - }, function optionalCallback(error, httpResponse, rebody) { 136 + url: "http://upload.static.yohobuy.com",
  137 + formData: {
  138 + fileData: req.body.files,
  139 + project: req.body.bucket
  140 + }
  141 + }, function optionalCallback(error, httpResponse, body) {
139 if (!error && httpResponse.statusCode == 200) { 142 if (!error && httpResponse.statusCode == 200) {
140 - var json = JSON.parse(rebody); 143 + var ret = JSON.parse(body);
  144 + if (ret.code === 200) {
  145 + var imgUrl = ret.data.imagesList[0];
  146 + imgUrl=Utils.joinImg(imgUrl);
141 result={}; 147 result={};
142 - result.originalName=json.data.substring(json.data.lastIndexOf('/')+1);  
143 - result.name=result.originalName;  
144 - result.url=json.data;  
145 - result.type=json.data.substring(json.data.lastIndexOf('.'));  
146 - result.state=json.message=="上传成功"?"SUCCESS":"FAIL"; 148 + if(imgUrl){
  149 + result.originalName=Date.now();
  150 + result.name=Date.now();
  151 + result.url=imgUrl;
  152 + result.type=imgUrl.substring(imgUrl.lastIndexOf('.'));
  153 + result.state="SUCCESS";
  154 + }else{
  155 + result.state="FAIL";
  156 + }
  157 + }
147 } 158 }
148 return callback(null, result); 159 return callback(null, result);
149 }); 160 });
@@ -82,6 +82,7 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo @@ -82,6 +82,7 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo
82 } else { 82 } else {
83 res.json(model); 83 res.json(model);
84 } 84 }
  85 + return;
85 }); 86 });
86 //调用接口获取数据 87 //调用接口获取数据
87 me.interfaces.require.apply(me.interfaces,[apis].concat(args)); 88 me.interfaces.require.apply(me.interfaces,[apis].concat(args));
@@ -158,6 +158,7 @@ Interfacer.prototype.require=function(mos,req,res,cb){ @@ -158,6 +158,7 @@ Interfacer.prototype.require=function(mos,req,res,cb){
158 console.error(results); 158 console.error(results);
159 return cb(err,results,names); 159 return cb(err,results,names);
160 } 160 }
  161 + console.log(names);
161 return cb(null, results, names); 162 return cb(null, results, names);
162 }); 163 });
163 }; 164 };