Couldn't catch the response through Angular file upload

Can someone help me to solve this AngularJS problem?

Another way, If I use $http POST method like this,

app.controller('MyCtrl', ['$scope','$http', function ($scope,$http) {
  $scope.uploadPic = function(file) { 
    method: 'POST',
    url: 'http://localhost:8080/openmrs/ws/rest/v1/module/?',
    headers: { 'Content-Type': 'multipart/form-data;boundary=gc0p4Jq0M2Yt08jU534c0p'},
    data: {file: file}

I am getting this following Error, [Required MultipartFile parameter 'file' is not present]

Can someone help me to resolve this issues?

I solved this problem, @dkayiwa It’s working :slight_smile:

The error message showed me like “Could not write JSON”. That means It could not write the JSON type response to the request. So I tried this manually and Identified, The response is based on application/xhtml+xml format. Then after, I changed my header with " ‘Accept’: 'application/xhtml+xml;charset=UTF-8’ ".

Finally, It works without any problems :grinning:.

Working Code for the POST request,

    $, fd, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined ,  'Accept': 'application/xhtml+xml;charset=UTF-8'}
    .success(function (data, status, headers, config) {
            $scope.PostDataResponse = data;
        .error(function (data, status, header, config) {