angularjs - Angular file uploading - 400 Bad Request -


i'm unsuccessfully trying upload file angular, continue 400 error. here code:

<div ng-app="app" ng-controller="ctrl"> <input type="file" name="file" onchange="angular.element(this).scope().uploadfile(this.files)"/> 

var app = angular.module("app", []); app.controller("ctrl", function ($scope, $http) {      $scope.uploadfile = function (files) {         var fd = new formdata();         //take first selected file         fd.append("file", files[0]);         $http                 .post('/upload', fd, {                     withcredentials: true,                     headers: {'content-type': undefined},                     transformrequest: angular.identity                 })                 .then(function mysucces(response) {                     alert('succes: ' + response.statustext);                 }, function myerror(response) {                     alert('error: ' + response.statustext);                 });     }; }); 

it's important notice ok server-side, because on same page i'm uploading file plain html:

<form action="/upload" method="post" enctype="multipart/form-data">         <div>             <input type="file" name="text">             <input type="submit">         </div> 

what doing wrong? i'm pretty unexperienced in frontend development appreciated help.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -