繁体   English   中英

上传文件node.js和angular强大

[英]upload file nodejs and angular 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.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);
      });
    };

我以前没有使用过。 但是ng-fileupload可以帮到您。 它简单而方便。 这是github文档。 https://github.com/danialfarid/ng-file-upload 希望对您有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM