Haseeb Wali
Haseeb Wali

Reputation: 1171

Spring rest controller's " MultipartFile[] multipartFiles" always recieves [ ] or null files

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

Upvotes: 3

Views: 3305

Answers (2)

Haseeb Wali
Haseeb Wali

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

shazin
shazin

Reputation: 21893

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

If not see this SO post

Upvotes: 1

Related Questions