2017-02-06 4 views
1

ng-file-uploadを使用して複数のファイルを同時にgrailsコントローラのアクションにアップロードしようとしています。しかし、私はアクションにアップロードされているファイルを保持する方法を把握することはできません。ng-file-uploadをgrailsで使用する方法2.5.3

は、ここに私のJSコードです:

app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) { 
    $scope.uploadFiles = function (files) { 
     $scope.files = files; 
     if (files && files.length) { 
      Upload.upload({ 
       url: 'http://localhost:8080/classifydemo/request/create', 
       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)); 
      }); 
     } 
    }; 
}]); 

そして、私のGrailsアクションは以下の通りです:

class RequestController { 

    def create() { 
     request.headerNames.each{ 
      println it 
     } 
     println params 
     println request.getFile("file") 
     render "test" 
    } 

} 

上記のコードはrequest.getFileに失敗しました。

質問は、どのように私はループ内でそれらを処理できるように、コントローラにアップロードされるファイルを手に入れることができます。

答えて

0

あなたが使用する必要があり、複数のファイルの可能性を持っているので:

request.fileNames.each { 
    MultipartFile file = request.getFile(it) 
    // do whatever you want with the file 
} 
+0

私はちょうどそれを試してみました、コードもその閉鎖を入力していないようです。また、要求のコンテンツタイプはnullだけです。 – Anthony

関連する問題