Javascript 邮递http://localhost:3000/upload 500(内部服务器错误)
我从客户端(angular.js)向服务器端(node.js)发送数据时出错。 我创建了一个表单,用户插入数据,然后我的控制器获取数据并将其发送到服务器,以将数据保存在mongoose和s3(amazon)中。 我必须说它工作得很好-我的意思是我可以保存我需要的所有信息,我可以在我的数据库中看到它,我可以在s3上看到图像 但是,我得到一个错误:Javascript 邮递http://localhost:3000/upload 500(内部服务器错误),javascript,angularjs,node.js,html,amazon-s3,Javascript,Angularjs,Node.js,Html,Amazon S3,我从客户端(angular.js)向服务器端(node.js)发送数据时出错。 我创建了一个表单,用户插入数据,然后我的控制器获取数据并将其发送到服务器,以将数据保存在mongoose和s3(amazon)中。 我必须说它工作得很好-我的意思是我可以保存我需要的所有信息,我可以在我的数据库中看到它,我可以在s3上看到图像 但是,我得到一个错误:POSThttp://localhost:3000/upload 500(内部服务器错误) 我的html表单: <html ng-app="myme
POSThttp://localhost:3000/upload 500(内部服务器错误)
我的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>
服务器端:
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个内部服务器错误,并且您将不知道发生了什么问题
始终处理错误。您有节点日志吗?500是一个一般性错误“我需要做什么?”——首先,显然也是当然:检查错误日志。这就是我得到的所有错误——在节点端它工作正常“在节点端它工作正常”——不,不是,否则节点不会告诉您存在内部服务器错误。确定如何在节点端检查日志错误?@CBroeI获取此错误类型错误:无法读取未定义的属性“file”
if (err) {
// ...
}