我使用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);
});
};发布于 2017-05-23 15:56:53
我以前没有用过这个。但是ng-fileupload可以帮到你。它既简单又方便。这就是github的文档。https://github.com/danialfarid/ng-file-upload。希望能对你有所帮助
https://stackoverflow.com/questions/44128558
复制相似问题