2016-03-24 10 views
1

私はng-file-uploadを使用してファイルをspring restサービスにアップロードしています。単一のファイルは正常にアップロードできますが、複数のファイルがある場合は失敗します。
私が使用するコードは以下の通りです:
はJavaScript:ng-file-spring restサービスへの複数のファイルのアップロード

    $scope.uploadFiles = function (files) { 
        $scope.files = files; 
        if (files && files.length) { 
         Upload.upload({ 
          url: 'http://localhost:8099/test/upload2', 
          data: {files: files} 
         }).then(function (response) { 
          $timeout(function() { 
           $scope.result = response.data; 
          }); 
         }, function (response) { 
          if (response.status > 0) { 
           $scope.errorMsg = response.status + ': ' + response.data; 
          } 
         }, function (evt) { 
          $scope.progress = Math.min(100, parseInt(100.0 * evt.loaded/evt.total)); 
         }); 
        } 
       }; 

のJava:

@ResponseStatus(HttpStatus.OK) 
@RequestMapping(value = "/upload2") 
public void upload2(@RequestParam("files") MultipartFile[] files) throws IOException { 
} 

しかし、ファイルの配列が空である、複数のファイルのための何か?

アップデート1:
私は以下のようにネットワーク]タブで要求を見ることができます:
リクエストを投稿する際にパラメータを追加することで解決

------WebKitFormBoundarywCLpwRaJRcmfPiBl 
Content-Disposition: form-data; name="username" 

qqq 
------WebKitFormBoundarywCLpwRaJRcmfPiBl 
Content-Disposition: form-data; name="files[0]"; filename="eagle.jpg" 
Content-Type: image/jpeg 


------WebKitFormBoundarywCLpwRaJRcmfPiBl 
Content-Disposition: form-data; name="files[1]"; filename="eclipse.epf" 
Content-Type: application/octet-stream 


------WebKitFormBoundarywCLpwRaJRcmfPiBl-- 

答えて

関連する問題