javascript - Multer not accepting files in array format gives 'Unexpected File Error' -
multer module used along node js , express upload files. using ng-file upload module on angular side.
when sending multiple files 1 one works fine without errors whatsoever when sending files in 1 go in array format , making necessary changes on server side suggested multer's github, still error comes.
here error
error: unexpected field @ makeerror (c:\nodefiles\new\node_modules\multer\lib\make-error.js:12:13) @ wrappedfilefilter (c:\nodefiles\new\node_modules\multer\index.js:39:19) @ busboy.<anonymous> (c:\nodefiles\new\node_modules\multer\lib\make-middleware.js:109:7) @ busboy.emit (events.js:118:17) @ busboy.emit (c:\nodefiles\new\node_modules\multer\node_modules\busboy\lib\main.js:31:35) @ partstream.<anonymous> (c:\nodefiles\new\node_modules\multer\node_modules\busboy\lib\types\multipart.js:209:13) @ partstream.emit (events.js:107:17) @ headerparser.<anonymous> (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\dicer.js:51:16) @ headerparser.emit (events.js:107:17) @ headerparser._finish (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\headerparser.js:70:8) @ sbmh.<anonymous> (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\headerparser.js:42:12) @ sbmh.emit (events.js:118:17) @ sbmh._sbmh_feed (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\node_modules\streamsearch\lib\sbmh.js:159:14) @ sbmh.push (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\node_modules\streamsearch\lib\sbmh.js:56:14) @ headerparser.push (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\headerparser.js:48:19) @ dicer._oninfo (c:\nodefiles\new\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\dicer.js:198:25)
sample controller code
var app = angular.module('fileupload', ['ngfileupload']); app.controller('myctrl', ['$scope', 'upload', '$timeout', function ($scope, upload, $timeout) { $scope.uploadfiles = function (files) { $scope.files = files; if (files && files.length) { console.log(files); upload.upload({ url: '/api/data/addtweet', data: { files: files } }).then(function (response) { $timeout(function () { $scope.result = response.data; }); }, function (response) { if (response.status > 0) { $scope.errormsg = response.status + ': ' + response.data; } }, function (evt) { $scope.progress = math.min(100, parseint(100.0 * evt.loaded / evt.total)); }); } }; }]);
please tell me i'm doing wrong. google searches not useful, have tried i.e.why posting here.
the reason error multer
not support array syntax ng-file-upload
uses default files[0]
, files[1]
, files[2]
, etc. multer
expecting series of files same field name.
the easiest solution set ng-file-upload
's arraykey
option avoid appending [index]
part:
upload.upload({ url: '/api/data/addtweet', arraykey: '', // default '[i]' data: { files: files } })
Comments
Post a Comment