本文介绍了Multer扔奇怪的错误,同时通过NG-文件上传文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了这个后,一些研究,我仍然不知道是怎么回事。在谷歌有不相关的搜索结果或给定的错误code /消息。
下面是我的角度控制,只是基于API的code和NG-文件上传NG-文件上传的样本。
VAR应用= angular.module('文件上传',['ngFileUpload']);app.controller('MyCtrl',['$范围','上传','$超时',函数($范围,上传,$超时){
的console.log(嘿嗬从控制器);
$ scope.uploadFiles =功能(文件){
$ scope.files =文件;
如果(文件和放大器;&安培; files.length){
的console.log(文件);
Upload.upload({
网址:'API /数据/检查',
数据:{
文件:文件
}
})。然后(功能(响应){
$超时(函数(){
$ scope.result = response.data;
的console.log(响应);
});
},函数(响应){
的console.log(响应);
如果(response.status大于0){
$ scope.errorMsg = response.status +:+ response.data;
的console.log(响应);
}
},功能(EVT){
的console.log(响应);
$ scope.progress =
Math.min(100,parseInt函数(100.0 * evt.loaded / evt.total));
});
}
};
}]);
这是code我已经写在服务器端。
app.post('/ API /数据/检查',merchants_offer_upload.single('文件'),功能(REQ,资源,下一个){
的console.log(req.body.merchantid);
的console.log(我们在这里);
// res.json({状态:0,picarray:array_pic});
});
我也试过这个问题,以及,我想这些在一个上载走,所以我想用数组上传功能
app.post('/ API /数据/检查',merchants_offer_upload.array('文件'),功能(REQ,资源,下一个){
的console.log(req.body.merchantid);
的console.log(我们在这里);
// res.json({状态:0,picarray:array_pic});
});
这是一个完整的存储code - 服务器
VAR merchant_storage = multer.diskStorage({
目的地:功能(REQ,文件,CB){ 的console.log(Multer第1部分婊子!)
MERCHANT_ID = req.params.merchantid;
的console.log(MERCHANT_ID);
的console.log('MERCHANT_ID:',MERCHANT_ID);
mkdirp(__目录名称+'/图片/报价/+ MERCHANT_ID,功能(错误){
的console.log(__目录名);
如果(ERR)console.error(ERR)
CB(NULL,__dirname +'/图片/报价/'+ MERCHANT_ID);
的console.log(heeeee 1);
});
},
文件名:功能(REQ,文件,CB){
的console.log(Multer部分2);
变种F = Date.now()+'_'+ file.originalname;
CB(NULL,Date.now()+ F)
array_pic.push(F);
的console.log(F);
的console.log(file.originalname); }
})VAR merchants_offer_upload = multer({存储:merchant_storage});
现在坏的部分。错误!
当我选择文件上传错误被抛出。
错误:意外现场
在makeError(C:\\ nodefiles \\新\\ node_modules \\ multer \\ LIB \\化妆error.js:12:13)
在wrappedFileFilter(C:\\ nodefiles \\新\\ node_modules \\ multer \\ index.js:39:19)
在打杂<&匿名GT; (C:\\ nodefiles \\新\\ node_modules \\ multer \\ LIB \\化妆middleware.js:109:7)
在Busboy.emit(events.js:118:17)
在Busboy.emit(C:\\ nodefiles \\新\\ node_modules \\ multer \\ node_modules \\打杂\\ lib目录\\ main.js:31:35)
在PartStream<&匿名GT; (C:\\ nodefiles \\新\\ node_modules \\ multer \\ node_modules \\打杂\\ lib目录\\ \\类型multipart.js:209:13)
在PartStream.emit(events.js:107:17)
在HeaderParser<&匿名GT; (C:\\ nodefiles \\新\\ node_modules \\ multer \\ node_modules \\打杂\\ node_modules \\切片机\\ lib目录\\ Dicer.js:51:16)
在HeaderParser.emit(events.js:107:17)
在HeaderParser._finish (C:\
odefiles\
ew\
ode_modules\\multer\
ode_modules\\busboy\
ode_modules\\dicer\\lib\\HeaderParser.js:70:8)
在SBMH<&匿名GT; (C:\
odefiles\
ew\
ode_modules\\multer\
ode_modules\\busboy\
ode_modules\\dicer\\lib\\HeaderParser.js:42:12)
在SBMH.emit(events.js:118:17)
在SBMH._sbmh_feed (C:\
odefiles\
ew\
ode_modules\\multer\
ode_modules\\busboy\
ode_modules\\dicer\
ode_modules\\streamsearch\\lib\\sbmh.js:159:14)
在SBMH.push (C:\
odefiles\
ew\
ode_modules\\multer\
ode_modules\\busboy\
ode_modules\\dicer\
ode_modules\\streamsearch\\lib\\sbmh.js:56:14)
在HeaderParser.push (C:\
odefiles\
ew\
ode_modules\\multer\
ode_modules\\busboy\
ode_modules\\dicer\\lib\\HeaderParser.js:48:19)
在Dicer._oninfo(C:\\ nodefiles \\新\\ node_modules \\ multer \\ node_modules \\打杂\\ node_modules \\切片机\\ lib目录\\ Dicer.js:198:25)
This is error messages I receive as response on the controller side
Hey ho from controller
controller6.js:12 [File]
angular.js:10661 POST http://localhost:1339/api/data/check 500 (Internal Server Error)(anonymous function) @ angular.js:10661sendReq @ angular.js:10480status.$get.serverRequest @ angular.js:10187processQueue @ angular.js:14634(anonymous function) @ angular.js:14650parent.$get.Scope.$eval @ angular.js:15916parent.$get.Scope.$digest @ angular.js:15727parent.$get.Scope.$apply @ angular.js:16024(anonymous function) @ angular.js:17791completeOutstandingRequest @ angular.js:5490(anonymous function) @ angular.js:5762
2angular.js:12416 ReferenceError: response is not defined
at controller6.js:30
at angular.js:14716
at Scope.parent.$get.Scope.$eval (angular.js:15916)
at Scope.parent.$get.Scope.$digest (angular.js:15727)
at Scope.parent.$get.Scope.$apply (angular.js:16024)
at done (angular.js:10511)
at completeRequest (angular.js:10683)
at XMLHttpRequest.requestLoaded (angular.js:10624)(anonymous function) @ angular.js:12416ident.$get @ angular.js:9203(anonymous function) @ angular.js:14718parent.$get.Scope.$eval @ angular.js:15916parent.$get.Scope.$digest @ angular.js:15727parent.$get.Scope.$apply @ angular.js:16024done @ angular.js:10511completeRequest @ angular.js:10683requestLoaded @ angular.js:10624
controller6.js:24 Object {data: "Error: Unexpected field<br> at makeEr…s\busboy\node_modules\dicer\lib\Dicer.js:198:25)↵", status: 500, config: Object, statusText: "Internal Server Error"}
controller6.js:27 Object {data: "Error: Unexpected field<br> at makeEr…s\busboy\node_modules\dicer\lib\Dicer.js:198:25)↵", status: 500, config: Object, statusText: "Internal Server Error"}
解决方案
The answer is that multer do not accept array in ng-upload module.
answer was given by @mscdex on other thread.
Multer not accepting files in array format gives 'Unexpected Filed Error'
The real answer credit goes to mscdex (http://stackoverflow.com/users/2050455/mscdex)
这篇关于Multer扔奇怪的错误,同时通过NG-文件上传文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!