javascript - Why does angular-file-upload result in 400 Bad Request? -


i trying follow angular-file-upload example npm site resulting in 400 bad request error, although not sure why. error on server end?

my html:

<input type="text" ng-model="mymodelobj"> <input type="file" ng-file-select="onfileselect($files)"> <button ng-click="upload.abort()">cancel upload</button>  

my module:

var myapp = angular.module('myapp', ['kendo.directives', 'ui.router', 'angularfileupload', 'data']); 

my controller:

myapp.controller('maincontroller',['$scope', 'dataservice', '$upload', function($scope, dataservice, $upload){   $scope.onfileselect = function($files) {   (var = 0; < $files.length; i++) {   var file = $files[i];   $scope.upload = $upload.upload({     url: myurl,     method: 'post',      headers: {             'authorization': 'bearer ' + token,             'accept': "application/json",              'content-type': undefined           },     data: {myobj: $scope.mymodelobj},     file: file      }).progress(function(evt) {      console.log('percent: ' + parseint(100.0 * evt.loaded / evt.total));    }).success(function(data, status){      console.log(data);    }).error(function(data, status){      console.log(status);    });  }; }]); 

i uploading single file now.

any appreciated, find debugging http requests pretty tricky.

update

it matter of including right fields in 'data'. structure below solved problem. may stupidity lesson all: make sure know data server-side expecting.

 url: myurl,  method: 'post',   headers: {           'authorization': 'bearer ' + token,           'accept': "application/json",           'content-type': undefined  },  data: {        'name': 'test',        'files': file   } 


Comments