3

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' PostMan Send Request

Haseeb Wali
  • 1,181
  • 3
  • 14
  • 34

2 Answers2

1

Have you configured the org.springframework.web.multipart.support.MultipartFilter?

If not see this SO post

Community
  • 1
  • 1
shazin
  • 21,379
  • 3
  • 54
  • 71
  • No it is automatically get configured with "public CommonsMultipartResolver multipartResolver()" method. As this is java config so we do't need xml. Beside that i have found the solution i am updating my answer, please if you find this question use full upvote it so that in future other persons can also get help. Thanks – Haseeb Wali Jul 01 '16 at 06:00
1

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.

Haseeb Wali
  • 1,181
  • 3
  • 14
  • 34