Authored by weiqingting

批量上传

... ... @@ -141,20 +141,7 @@ edit.prototype={
Temp+='</ul>';
$(this).after(Temp);
});
edit.ajaxfileupload(that.el+" input[type='file']",{
'params':{"userId":543883,"bucket":'smart'},
'onComplete': function(response) {
var _w=$(this).next().find('.fileinput-button-icon');
if(_w.find('img').length>0){
_w.find('img').attr("src",response.data);
}else{
_w.prepend('<img width="76" height="80" src="'+response.data+'">');
}
$(this).attr("value",response.data);
}
});
// $('input[type="file"]',that.el).ajaxfileupload({
// 'action': '/ajax/upload',
// edit.ajaxfileupload(that.el+" input[type='file']",{
// 'params':{"userId":543883,"bucket":'smart'},
// 'onComplete': function(response) {
// var _w=$(this).next().find('.fileinput-button-icon');
... ... @@ -164,12 +151,25 @@ edit.prototype={
// _w.prepend('<img width="76" height="80" src="'+response.data+'">');
// }
// $(this).attr("value",response.data);
// },
// 'onStart': function() {
// },
// 'onCancel': function() {
// }
// });
$('input[type="file"]',that.el).ajaxfileupload({
'action': '/ajax/upload',
'params':{"userId":543883,"bucket":'smart'},
'onComplete': function(response) {
var _w=$(this).next().find('.fileinput-button-icon');
if(_w.find('img').length>0){
_w.find('img').attr("src",response.data);
}else{
_w.prepend('<img width="76" height="80" src="'+response.data+'">');
}
$(this).attr("value",response.data);
},
'onStart': function() {
},
'onCancel': function() {
}
});
}
that.__listen("render");
... ...
... ... @@ -8,15 +8,19 @@ exports.uploadFile=function(req,res){
// 方法1
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){
// 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:"请求类型错误"});
... ... @@ -27,11 +31,5 @@ exports.uploadFile=function(req,res){
// "message":"success"
// });
//方法2
// req.pipe(request.post(domain+'/fileupload/upload'))
// .on('error', onerror)
// .pipe(res);
// function onerror(err) {
// console.error(err.stack)
// }
}
\ No newline at end of file
... ...