Multipart File upload using Springfox and Swagger-ui
In my situation, there were two things I needed to do
- My MultipartFile request param had to be named 'file', otherwise, swagger-ui wouldn't display the file upload input control
@RequestParam("file") MultipartFile file
- I had to register the following bean
@Bean(name = "multipartResolver")public CommonsMultipartResolver commonsMultipartResolver(){ return new CommonsMultipartResolver();}
I think you are missing the consumes attribute of the @RequestMapping in your second snippet. See the following example
@RequestMapping( path = "/upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)public ResponseEntity<String> handleUpload( @RequestPart("file") MultipartFile file, @RequestParam("someId") Long someId, @RequestParam("someOtherId") Long someOtherId) { return new ResponseEntity<>();}
Use
@RequestPart(required = true) MultipartFile file
And use the version number 2.1.0 or latest, there is a bug with previous versions.