這是我收到的控制檯角JS快遞JS文件上傳拋出錯誤,不確定是不是函數
TypeError: undefined is not a function
at C:\nodefiles\new\server.js:101:16
at Layer.handle [as handle_request] (C:\nodefiles\new\node_modules\express\lib\router\layer.js:95:5)
at next (C:\nodefiles\new\node_modules\express\lib\router\route.js:131:13)
at done (C:\nodefiles\new\node_modules\multer\lib\make-middleware.js:36:7)
at indicateDone (C:\nodefiles\new\node_modules\multer\lib\make-middleware.js:40:51)
at C:\nodefiles\new\node_modules\multer\lib\make-middleware.js:142:11
at WriteStream.<anonymous> (C:\nodefiles\new\node_modules\multer\storage\disk.js:43:9)
at WriteStream.emit (events.js:129:20)
at finishMaybe (_stream_writable.js:484:14)
at afterWrite (_stream_writable.js:362:3)
at onwrite (_stream_writable.js:352:7)
at WritableState.onwrite (_stream_writable.js:105:5)
at fs.js:1799:5
at FSReqWrap.strWrapper (fs.js:568:5)
上的錯誤這是我的HTML頁面
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<style>
.thumb {
width: 24px;
height: 24px;
float: none;
position: relative;
top: 7px;
}
form .progress {
line-height: 15px;
}
.progress {
display: inline-block;
width: 100px;
border: 3px groove #CCC;
}
.progress div {
font-size: smaller;
background: orange;
width: 0;
}
</style>
</head>
<body ng-app="fileUpload" ng-controller="MyCtrl">
<h4>Upload on file select</h4>
<button ngf-select="uploadFiles($files)" multiple
accept="image/*" ngf-max-height="1000" ngf-max-size="1MB">
Select Files</button>
<br><br>
Files:
<ul>
<li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}}
<span class="progress" ng-show="f.progress >= 0">
<div style="width:{{f.progress}}%"
ng-bind="f.progress + '%'"></div>
</span>
</li>
</ul>
{{errorMsg}}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script src="controller3.js"></script>
<script src="https://angular-file-upload.appspot.com/js/ng-file-upload-shim.js"></script>
<script src="https://angular-file-upload.appspot.com/js/ng-file-upload.js"></script>
</body>
</html>
這是我的控制器
//inject angular file upload directives and services.
var app = angular.module('fileUpload', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadFiles = function(files) {
$scope.files = files;
angular.forEach(files, function(file) {
if (file && !file.$error) {
file.upload = Upload.upload({
url: '/api/data',
file: file
});
file.upload.then(function (response) {
$timeout(function() {
file.result = response.data;
});
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
});
file.upload.progress(function (evt) {
file.progress = Math.min(100, parseInt(100.0 *
evt.loaded/evt.total));
});
}
});
}
}]);
這是我在服務器端代碼
var multer = require('multer');
var upload = multer({
dest: __dirname + '/public',
});
app.post('/api/data', upload.single('file'), function (req, res, next) {
console.log("We are here fellas");
return res.ok();
});
我認爲這個問題是因爲我在後端編寫代碼的最後提到的那件事。我正在學習幾個教程,因爲我對這個主題很陌生。
我跟隨Danial Farid的github,他做了nf-fileupload的事情。
請幫我解決這個錯誤。
對不起,如果我聽起來很愚蠢,我是新來的。
我不知道這是否是必要的,但,這是我得到我的前端選擇文件(在谷歌Chrome開發者控制檯)後的誤差
angular.js:10661 POST http://localhost:1339/api/data 500 (Internal Server Error)
什麼在C:\ nodefiles \ new \ server.js:101:16? – bluesman
return res.ok();現在我已經評論過了,代碼工作正常。謝謝大家。 –