[英]isAxiosError.js:12 POST http://localhost:3000/cartdata 500 (Internal Server Error)
[英]POST http://localhost:3000/upload 500 (Internal Server Error)
從客戶端(angular.js)向服務器端(node.js)發送數據時出現錯誤。 我創建了一個表單,供用戶插入數據,然后我的控制器獲取數據並將其發送到服務器,以將數據保存在mongoose和s3(amazon)中。 我必須說它可以正常工作-我的意思是我可以保存所有需要的信息,可以在數據庫中看到它,也可以在s3上看到圖像
但是,我收到一個錯誤: POST http://localhost:3000/upload 500 (Internal Server Error)
我的html表格:
<html ng-app="mymed">
<head>
<title>insert</title>
</head>
<body ng-controller="tryController">
<main>
<body>
<form class="form-group" enctype="multipart/form-data" method="POST" action="http://localhost:3000/upload">
<label for="inputEmail3" class="col-sm-2 control-label">Title:</label>
<input class="form-control" type="text" placeholder="Title" ng-model="Title" name="Title" required></input>
</div>
<div class="col-sm-10">
<br>
<input type="file" name="file" accept="image/*" ng-modle="file"></input>
</div>
</div>
<input type="submit" class="btn btn-default" name="send" ng-click="createInsert()"></input>
</form>
.....
<script src="js/appController.js"></script>
我的控制器:
mymedical.controller('tryController',['$scope','$http','$cookies', function($scope,$http,$cookies){
$scope.createInsert = function(){
var data = {};
data.Title = $scope.Title;
data.file = $scope.file;
$http.post('http://localhost:3000/upload', JSON.stringify(data)).then() //callback
}
}]);
切斷側:
exports.saveDatatry=function(request, response){
console.log(request.body);
var file = request.files.file;
var hash = hasher();
var stream = fs.createReadStream(file.path)
var mimetype = mime.lookup(file.path);
console.log(stream);
var req;
if (mimetype.localeCompare('image/jpeg')
|| mimetype.localeCompare('image/pjpeg')
|| mimetype.localeCompare('image/png')
|| mimetype.localeCompare('image/gif')) {
req = client.putStream(stream, hash+'.png',
{
'Content-Type': mimetype,
'Cache-Control': 'max-age=604800',
'x-amz-acl': 'public-read',
'Content-Length': file.size
},
function(err, result) {
var savePerTry = new personal({
Title: request.body.Title,
file: req.url
});
savePerTry.save(function(error, result) {
if (error) {
console.error(error);
} else {
console.log("saved!");
response.redirect('http://localhost:8080/tryinsert.html');
};
})
});
} else {
console.log(err);
}
}
我需要做什么? 謝謝,
這是您的問題:
function(err, result) {
var savePerTry = new personal({
Title: request.body.Title,
file: req.url
});
每次您編寫如下內容:
function(err, result) {
那么下一行應該是:
if (err) {
// ...
}
當您不處理錯誤時,將收到500個內部服務器錯誤,並且您將不知道出了什么問題。
始終處理錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.