I'm using Spring MVC as a rest controller and I've integrated Swagger-ui with my controller using Springfox. I'd like to have a method that is able to upload a file via the Swagger-ui interface. I only need two parameters, a long acting for an object id and the file to be uploaded.
@RestController
public class controller{
@RequestMapping(value="/upload", method=RequestMethod.POST)
public void uploadFile(@RequestParam Long id,
@RequestParam MultipartFile file){
//do some stuff
}
}
I've tried almost everything and I can't get a file upload button to appear. However, if I do:
@RestController
public class Controller{
@RequestMapping(value="/upload", method=RequestMethod.POST)
public void uploadFile(@RequestParam Long id,
@RequestPart File file){
//do some stuff
}
}
The file upload button appears, but it always throws http code 415 when trying to upload a file. Besides, I need the input to be a MultipartFile, not a regular File. Even if I use the @RequestPart annotation with Multipart File, the choose file to upload button does not appear. How can I get this to work???? Even:
@RestController
public class Controller{
@RequestMapping(value="/upload", method=RequestMethod.POST)
public void uploadFile(@RequestPart String metaData,
@RequestPart MultipartFile file){
//do some stuff
}
}
Won't work. If someone could give a walkthrough of how to get this button to appear for MultipartFile? I'd be forever grateful.