Authored by weiqingting

图片上传

... ... @@ -54,9 +54,6 @@ module.exports=function(app) {
app.post("/productColor/queryProductColors","basegoods_queryProductColors");
/*获取(非)销售属性*/
app.post("/standard/queryAllBySortId4Html","basegoods_queryAllProductAttr");
app.post("/product/queryMaterialList","basegoods_queryMaterialList");
app.post("/product/querySortBySmallSort","basegoods_querySortBySmallSort");
... ...
... ... @@ -130,20 +130,31 @@ module.exports={
result={code: "501",message: "用户失效,请重新登录"};
return callback(null, result);
}
req.body.file = fs.createReadStream(req.files.upfile.path);
req.body.files = [fs.createReadStream(req.files.upfile.path)];
req.body.bucket="goodsimg";
request.post({
url: config.domain + '/fileupload/upload',
formData: req.body
}, function optionalCallback(error, httpResponse, rebody) {
url: "http://upload.static.yohobuy.com",
formData: {
fileData: req.body.files,
project: req.body.bucket
}
}, function optionalCallback(error, httpResponse, body) {
if (!error && httpResponse.statusCode == 200) {
var json = JSON.parse(rebody);
result={};
result.originalName=json.data.substring(json.data.lastIndexOf('/')+1);
result.name=result.originalName;
result.url=json.data;
result.type=json.data.substring(json.data.lastIndexOf('.'));
result.state=json.message=="上传成功"?"SUCCESS":"FAIL";
var ret = JSON.parse(body);
if (ret.code === 200) {
var imgUrl = ret.data.imagesList[0];
imgUrl=Utils.joinImg(imgUrl);
result={};
if(imgUrl){
result.originalName=Date.now();
result.name=Date.now();
result.url=imgUrl;
result.type=imgUrl.substring(imgUrl.lastIndexOf('.'));
result.state="SUCCESS";
}else{
result.state="FAIL";
}
}
}
return callback(null, result);
});
... ...
... ... @@ -82,6 +82,7 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo
} else {
res.json(model);
}
return;
});
//调用接口获取数据
me.interfaces.require.apply(me.interfaces,[apis].concat(args));
... ...
... ... @@ -158,6 +158,7 @@ Interfacer.prototype.require=function(mos,req,res,cb){
console.error(results);
return cb(err,results,names);
}
console.log(names);
return cb(null, results, names);
});
};
... ...