Reputation: 1171
I am using Spring 4 with Java Config. I want multiple files to be uploaded to the server but problem is my MultipartFile[ ] parameter will always receive empty/[ ] parameter. Let me share my code here is my 'AppConfig'
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver(){
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setDefaultEncoding("utf-8");
commonsMultipartResolver.setMaxUploadSize(50000000);
return commonsMultipartResolver;
}
So i registered my multipartResolver after that i wrote this controller which is doing nothing but receiving files.
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public List<PutObjectResult> upload(@RequestParam("file") MultipartFile[] multipartFiles) {
System.out.println("Multipart file length is "+multipartFiles.length);
return s3Wrapper.upload(multipartFiles);
}
Here my MultipartFile[] multipartFiles is always empty/[ ] no matter how much images/files i send from my client. I am using 'PostMan' to send my files here is screen shot attached of sending request to multipart controller from 'postMan'
Upvotes: 3
Views: 3305
Reputation: 1171
I solved this problem just by putting a form in jsp and test my method with form submit. Also i used HttpClient, for sending request and it worked. I am not able to understand why but somehow the issue is with 'PostMan' tool through which i was hitting my restcontroller.
Upvotes: 1