2016-11-22 7 views
0

フロントエンド(angularjs)にExcelファイルをアップロードしていて、バックエンド(grailsリソースファイル)で受け取っています。GSPをプロジェクトで使用するはずがありません.Angeljs経由で送信されたファイルを受け取る方法?grails(バックエンド)のangularjsからアップロードされたファイルを受け取る方法は?

AngularJsコード、

$scope.uploadExcelFile =function (file) { 
     var doc = file 
     var filesArr = []; 
     if (doc) { 
      filesArr.push({file: doc}); 
      uploadCurry(filesArr); 
     } 
    } 
    function uploadCurry(queue){ 
     if (arguments.length) { 
      this.q = queue 
     } 
     if (this.q.length) { 
      var curr = this.q.pop(); 
      upload(curr.file); 
     } 
    } 
    function upload(file) { 
     if (file) { 
      var postdata = { 
       file: file, 
      } 
      roleProfileService.importExcleFile(postdata).then(function(res) { 
       console.log(res); 
      }) 
     } 
    } 

角度サービスファイル、

var importExcleFile = function(file,callback){ 

     return $upload.upload({ 
      url: '/api/importFile/profile', 
      method: 'POST', 
      file: file 
     }).progress(function(evt) { 
      _log('progress: ' + parseInt(100.0 * evt.loaded/evt.total) + '% file :'+ evt.config.file.name); 
      roleProfileService.progress = 'Loading '+ evt.config.file.name +" : "+ parseInt(100.0 * evt.loaded/evt.total)+"%" 
     }).success(function(data, status, headers, config) { 
      _log('file ' + config.file.name + 'is uploaded successfully. Response: ' + data); 
      roleProfileService.uploadsuccess = true; 
      if(callback) callback(); 


     }).error(function(a,b,c,d,e){ 
      _log("err", a,b,c,d,e); 
      roleProfileService.uploadfail = true; 
     }); 
    } 

Grailsのリソースファイル、

@Path('/api/importFile') 
@Consumes(['application/json','text/plain','application/vnd.ms-excel']) 
@Produces(['application/json']) 

class KsaResource { 
    KsaService ksaService 

    @GET 
    @Path('profile') 
    Response getAllKsaData(MultipartFile file) { 
     //how to receive uploaded file here? 
     List<Job> jobSavedList = ksaService.importExcelData(file); 
     //rest of code 
    } 
} 

答えて

0

私たちは、ファイル

class ImportRoleProfileController { 

    SpringSecurityService springSecurityService; 

    def importUpload() { 
     User currentUser = springSecurityService.getCurrentUser(); 
     def file = request.getFile('file') 
     Workbook workbook = Workbook.getWorkbook(file.getInputStream()); 
     int sheet_Num = workbook.getNumberOfSheets(); 
を受信するためのコントローラを書くことができます
関連する問題