how to upload a file in Restangularjs using multipart/formdata

我的梦境 提交于 2019-12-10 23:54:28

问题


my html code

<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>

Thanks for your help


回答1:


This piece of code worked for me....

$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})
            };


来源:https://stackoverflow.com/questions/33730489/how-to-upload-a-file-in-restangularjs-using-multipart-formdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!