如何使用multipart / formdata在Restangularjs中上传文件

Roh*_*ade 2 angularjs angular-file-upload

我的html代码

<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>
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

Roh*_*ade 5

这段代码为我工作。

$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})
            };
Run Code Online (Sandbox Code Playgroud)

  • 你能解释一下你的答案吗 (2认同)