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>

Thanks for your help


This piece of code worked for me….

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

Answered By – Rohan Kawade

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.