我使用formidable上传带有angular和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.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
<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);
});
};
答案 0 :(得分:3)