多个文件上传使用ajax和spring boot总是返回null

时间:2017-03-17 17:36:37

标签: jquery ajax spring

   when i try to upload multiple files, MultipartFile [] trainerProvider  in the trainer controller is null.
below is the code, please do help me out.
     

trainer.jsp

$(function() {      $("form#data").submit(function(event){

  event.preventDefault();

  var url  = '${pageContext.request.contextPath}/eduskill/trainer/upload';

  var trainerProviderLogo = document.getElementById("trainingProviderLogo".files);

  var formData = new FormData();
  formData.append("trainerProviderLogo", trainerProviderLogo);

  $.ajax({
    url: url,
    type: 'POST',
    data: formData,
    async: false,
    cache: false,
    contentType: false,
    processData: false,
    success: function (status) {
      // do something on success
     }
  });

  return false;

});
     

});

<form id="data">
   <div class="form-inline row">
                          <label class="col-md-4">Training Provider Logo:</label> <input
                              class="col-md-5 new1-col" type="file"
                              name="trainerProviderLogo[]" multiple="multiple"
                              id="trainingProviderLogo" accept="image/*">
                      </div>
</form>
     

培训师控制器

@RequestMapping(value = { ControllerUriConstant.upload }, method = RequestMethod.POST)    public  @ResponseBody String becomeTrainer(
      @RequestParam("trainerProviderLogo") MultipartFile[]
     

trainerProviderLogo)抛出IOException,TechnoShineException {}

     

[从ajax方面上传的数据] [1]

     
    
      

[1]:https://i.stack.imgur.com/PCrcl.png

    
  

0 个答案:

没有答案