繁体   English   中英

使用Angular和Node上传文件

[英]File upload using Angular and Node

我正在努力实现以下目标:

  • 客户上传简历作为表单的一部分
  • AngularJS将所有表单数据(包括CV)发送到Node服务器
  • 节点将简历存储在服务器上

我似乎无法正常工作。 我尝试使用multer无济于事。

到目前为止,我有以下几点:

的HTML

<form name="register" enctype="multipart/form-data" method="post" ng-submit="registerSubmit(user)">
  <input type="email" placeholder="Email" ng-model="user.email" />
  <input type="file" id="cv" name="cv" ng-model="user.cv" />
  <button type="submit"></button>
</form>

角度的

app.controller("MainController", function($scope, $http){

  $scope.registerSubmit = function(user){
    $http.post("/api/register", user).success(function(data){
      console.log(data);
    });
  });

});

节点 (配置有Express和其他模块)

app.use("/api", router);
router.post("/api/register", function(req, res){
  //file not coming through and not sure what to do with it here anyway!
});

您必须将您的请求编码为“ multipart / form-data”。 检查这个类似的问题: 使用$ http上传文件

暂无
暂无

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

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