Empty List when trying to upload many files in Spring with ng-file-upload

前端 未结 5 1038
遇见更好的自我
遇见更好的自我 2020-12-14 02:39

I have the following controller method for uploading multiple files at once, inspired by this blog post and answers to this question as well:

@RequestMapping         


        
5条回答
  •  情深已故
    2020-12-14 03:03

    The problem was that ng-file-upload by default submits array of files using names file[0], file[1] etc. It is configurable with the arrayKey value when using Upload Service. Setting it to empty string forces the files to be sent under the same file key, which is correctly resolved with Spring and the @RequestParam("file") List contains all files that has been submitted.

    Upload.upload({url: url, data: {file: arrayOfFiles}, arrayKey: ''})
    

提交回复
热议问题