Error message = Missing MultipartFile parameter "file" parameter

Testing the spring file upload form, the controlelr signature looks like this:

@RequestMapping(value = "upload", method = RequestMethod.POST) @ResponseBody public void upload(@RequestParam("file") MultipartFile multipartFile) {} 

and check it out

 final MockMultipartFile file = new MockMultipartFile("content", "myFile.txt", "text/plain", "hello".getBytes()); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = .fileUpload("/upload/") .file(file) .accept(MediaType.APPLICATION_JSON); 

but I get the above: Error message = Required "File" parameter of MultipartFile parameter is missing

+4
source share
1 answer

You named the parameter as "file", not as "content":

Edit:

 new MockMultipartFile("content", "myFile.txt", "text/plain", "hello".getBytes()); 

To:

 new MockMultipartFile("file", "myFile.txt", "text/plain", "hello".getBytes()); 
+7
source

Source: https://habr.com/ru/post/1502460/


All Articles