Javascript 上传文件nodejs和nodejs
我使用强大的上传文件与角度和nodejs。但我无法将任何内容发布到服务器。以下是我尝试过的代码: 服务器Javascript 上传文件nodejs和nodejs,javascript,angularjs,node.js,formidable,Javascript,Angularjs,Node.js,Formidable,我使用强大的上传文件与角度和nodejs。但我无法将任何内容发布到服务器。以下是我尝试过的代码: 服务器 var form = new formidable.IncomingForm(); form.uploadDir = path.join(__dirname, '../public/uploads'); form.on('file', function(field, file) { fs.rename(file.path,path.join(form.upload
var form = new formidable.IncomingForm();
form.uploadDir = path.join(__dirname, '../public/uploads');
form.on('file', function(field, file) {
fs.rename(file.path,path.join(form.uploadDir,file.name),function(err) {
if(err)
console.log(err);
console.log('Success')
});
});
// log any errors that occur
form.on('error', function(err) {
console.log('An error has occured: \n' + err);
});
// parse the incoming request containing the form data
form.parse(req, function(err, fields, files) {
});
})
Html
我以前没用过这个。但是ng fileupload可以帮你的忙。它简单方便。这是github的文档。希望它能对你有所帮助我以前没有用过这个。但是ng fileupload可以帮你的忙。它简单方便。这是github的文档。希望它对您有所帮助将action=“/customers/message”添加到您的表单标签并删除ng submit。在表单中也使用method=“post”tag@Dinesh我编辑问题。我还想要输入文本的post文件尝试使用这个@Dinesh现在它post文件成功了,但是我如何才能在input中获取数据您可以使用文本字段的隐藏输入类型并提交它。例如,将action=“/customers/message”添加到表单标签并删除ng submit。在表单中也使用method=“post”tag@Dinesh我编辑问题。我还想要输入文本的post文件尝试使用这个@Dinesh现在它post文件成功了,但是我如何才能在input中获取数据您可以使用文本字段的隐藏输入类型并提交它。谢谢你的帮助,但我现在不能用这个。我非常感谢你的帮助,但我现在不能用这个。投票通过
<form enctype="multipart/form-data" class="form-horizontal" role="form" id = "form_email" ng-submit="pushMessage()">
$scope.formMessage={};
$scope.pushMessage = function() {
$http.post('/customers/message',$scope.formMessage).then(function(response) {
console.log(response);
});
};