Send file using PUT method Angularjs
<p>I am using angularjs. I have created a file upload function using angularjs with laravel. The file upload with FormData is working fine. But when I try to send file through PUT method there is no response from the server side.</p>

<p>I have gone through the following answers.
<a href="https://stackoverflow.com/questions/10840972/uploading-a-file-with-jquery-and-sending-as-a-put">Uploading a file with jquery and sending as a PUT</a> and <a href="https://stackoverflow.com/questions/5518420/how-to-upload-a-file-using-an-http-put-using-jquery">How to upload a file using an HTTP &quot;PUT&quot; using JQuery?</a> but I cannot able to find solution.</p>

<p>Here is my code.</p>

<pre><code>&lt;input type="file" ng-file-model = "formData.files" multiple&gt;
</code></pre>

<p>The directive for my code</p>

<pre><code>app.directive('ngFileModel', ['$parse', function ($parse) {
return {
    restrict: 'A',
    link: function (scope, element, attrs) {
        var model = $parse(attrs.ngFileModel);
        var isMultiple = attrs.multiple;
        var modelSetter = model.assign;
        element.bind('change', function () {
            var values = [];
            angular.forEach(element[0].files, function (item) {
                var value = item;
                values.push(value);
            });
            scope.$apply(function () {
                if (isMultiple) {
                    modelSetter(scope, values);
                } else {
                    modelSetter(scope, values[0]);
                }
            });
        });
      }
    };
}]);
</code></pre>

<p>Here is my function which converts my form data into FormData</p>

<pre><code>constructFormData : function( data ) {
  var fd = new FormData();
  for (var key in data) {
    var value = data[key];
    angular.forEach(data, function (file, i) {
      fd.append('files['+i+']', file);
    });
  }
  return fd;
}, 
</code></pre>

<p>Here is my Controller</p>

<pre><code>var formData = GeneralService.constructFormData($scope.formData);
FileService.update( formData )
  .success(function( data ){
      if(data.status == 403) {
        $location.path('/403');
      }
      if(data.success) {
          console.log(data);
      } else {
        ValidationService.showValidationErrors(data.errors);
      }
  });
</code></pre>

<p>Here is my service</p>

<pre><code>update : function(formData) {
  return $http({
        method: 'PUT',
        url: $rootScope.baseurl +'/files',
        data: formData,
        dataType: 'json',
        headers: {'Content-Type': undefined}
    });
},
</code></pre>

<p>The Server side (laravel)</p>

<p><strong>routes.php</strong></p>

<pre><code>Route::put('/files', ['uses' =&gt; 'FilesController@update']);
</code></pre>

<p><strong>FilesController</strong></p>

<pre><code>public function update(Request $request) {
  $data = $request-&gt;all();
  print_r($data);
}
</code></pre>

<p>the above <code>print_r</code> function displays nothing.</p>

<p>I am get the posted data using <code>print_r($request-&gt;all());</code>, It gives empty data. I don't know where I make mistake. If I am asking this question by wrong please apologize.</p>