Search code examples
angularjsangular-resource

How to send the `form data` with id's in angular resource save method?


I need to save the data using angular save method ( 'post'). how can i send the necessary id is with form data?

at present i am getting an error as 'Invalid HTTP status code 405`.

here is my controller.js:

$scope.uploadFile = function ( newFile, id ) {
    var data = new FormData();

    server.uploadXML.save({
    //passing id's
        packageId: $scope.packageId, 
        contractorId : $scope.contractorId,
        contractId : id

    }, { save: {
        //passing data..is it correct?
        data: newFile[0]
    }}); 
}

here is my server.js:

(function () {
    "use strict";
    angular
    .module("tcpApp")
    .factory("server", ['$resource', function ($resource) {

        var base = 'http://azvsptcsdev02:678/_vti_bin/CPMD.WEBSERVICE/ProjectInfoService.svc/';

        return {
            uploadXML   : $resource( base + 'UploadContract/:packageId/:contractorId/:contractId')
        }
    }]);
})();

Solution

  • You need to specify which type of request it is.. GET/POST/PUT etc

    405 comes when the method is not allowed, which means either the request type is wrong or the endpoint is not defined.

    Hope this helps.