how to upload a file in Restangularjs using multipart/formdata

Problem

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

Problem courtesy of: Rohan Kawade

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})
            };
Solution courtesy of: Rohan Kawade

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.