Spring Boot ng-file-upload错误请求400

时间:2016-03-24 11:33:07

标签: javascript angularjs html5 spring-mvc ng-file-upload

所以我尝试使用SPRING和angular ng-file-upload上传pdf文件。我收到Bad Request 400回复。任何建议???

HTML:

<div ngf-drop ngf-select ng-model="files" class="drop-box" file  model="fileModel" 
  ngf-drag-over-class="{ accept:'dragovercorrect', reject:'dragoverincorrect'}" 
  ngf-multiple="true" ngf-allow-dir="true" accept="application/pdf" 
  ngf-pattern="'application/pdf'">Drag pdf or click to upload</div>

JS:

angular.module('webConverterFrontendApp').controller('ConverterController', ['$scope', 'Upload', '$timeout',
  function($scope, Upload, $timeout) {
    $scope.$watch('files', function() {
      $scope.upload($scope.files);
    });
    $scope.$watch('file', function() {
      if ($scope.file != null) {
        $scope.files = [$scope.file];
      }
    });
    $scope.log = '';

    $scope.upload = function(files) {
      if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
          var file = files[i];
          if (!file.$error) {
            console.log(file.size);
            Upload.upload({
              url: 'http://localhost:8080/upload',
              data: {
                'file': file
              }
            }).success(function() {
              console.log('success');
            });
          }
        }
      }
    };
  }
]);

Spring控制器:

@CrossOrigin(origins = "http://localhost:9000")
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(@RequestParam("file") MultipartFile file) throws IOException {

    System.out.println("received file named: " + file.getOriginalFilename());
}

结果我得到了:

enter image description here

0 个答案:

没有答案