2015-11-16 21 views
1

我的HTML代码如何使用多/ FORMDATA

<form method="post" enctype="multipart/form-data" ng-controller="commentCtrl" name="form"> 
     <a href="" type="file" class="custom-height"><img src="source/assets/images/icons/icofileattached.png" class="attachmentpng-height" ngf-select="uploadFiles($file)" ng-model="files"/></a> 
     <md-button type="submit" class="md-raised custom-submit-button" ng-click="MakeComments()"> SUBMIT </md-button> 
     </form> 

感谢您的帮助

+1

这里上传文件Restangularjs你可以找到一个指令'ng-file-upload' https://github.com/danialfarid/ng-file-upload –

+0

[File Upload without Form]的可能重复(http://stackoverflow.com/questions/19617996/)文件上传没有形式) – azerafati

回答

4

这段代码工作对我来说....

$scope.uploadFiles = function(file) { 
       console.log(file); 
       $scope.fileData = file; 
       var fd = new FormData(); 
       fd.append('file', file); 
       Restangular.one('/api/files/end points').withHttpConfig({transformRequest: angular.identity}) 
        .customPOST(fd, '', undefined, {'Content-Type': undefined}) 
      }; 
+0

你能解释你的答案吗? – rohanagarwal