Authored by liuyue

upload

... ... @@ -421,8 +421,8 @@ $('#sure-change').on('click', function() {
});
data = JSON.stringify(arr);
common.util.__ajax({
console.log(data);
/*common.util.__ajax({
url: '/goods/batchUpdatePrice',
data: {
batchList: data
... ... @@ -431,7 +431,7 @@ $('#sure-change').on('click', function() {
$('#priceTable').hide();
$('.success-wrap').show();
path = res.data;
});
});*/
});
$('#download-btn').on('click', function() {
... ...
var request = require('request');
var _ = require('lodash');
var fs = require('fs');
var ipaddr = require('ipaddr.js');
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.162:8088/platform';
var env = process.env.NODE_ENV || 'development';
exports.uploadFile = function(req, res) {
if(req.session.user) {
appendAdminInfo(req,req.session.user.auth);
var headers = {};
if (req.session && req.session.user) {
var ipObject = ipaddr.process(req.ip).octets
var ip = ipObject ? ipObject.join('.') : req.ip;
headers = {
'x-user-id': req.session.user.pid,
'x-user-name': req.session.user.account,
'x-site-type': 1,
'x-client-ip': ip
};
}
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({
var options = {
url: domain + '/batch/import',
formData: req.body
}, function optionalCallback(err, httpResponse, body) {
method: 'POST',
formData: req.body,
headers: headers
};
request(options, function(error, response, body) {
var json = JSON.parse(body);
json.status = true;
res.json(json);
});
// request.post({
// url: domain + '/batch/import',
// formData: req.body,
// headers: headers
// }, function optionalCallback(err, httpResponse, body) {
// var json = JSON.parse(body);
// json.status = true;
// res.json(json);
// });
} else {
request.post({
url: domain + '/fileupload/upload',
... ... @@ -39,20 +62,3 @@ exports.uploadFile = function(req, res) {
});
}
}
\ No newline at end of file
/**
* 附加管理员的信息
* @param {Request} req 请求对象
* @param {Number} uid 用户ID
* @param {String} name 用户名
* @return {Object} 用户信息对象
*/
function appendAdminInfo(req,auth) {
var ipObject = ipaddr.process(req.ip).octets
var ip = ipObject?ipObject.join('.'):req.ip;
req._yoheaders = {
'x-user-id':auth.pid,
'x-user-name':auth.account,
'x-site-type':WEBSITE,
'x-client-ip':ip
};
}
\ No newline at end of file
... ...