angularjsangular-file-upload

how to upload a file in Restangularjs using multipart/formdata


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


Solution

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