I have a service where I want to be able to optionally upload a file (including a file will run a separate function) with a POST request.
A simplified version of what my ReqestMapping looks like is this:
@ApiOperation(value = "Data", nickname = "Create a new data object") @RequestMapping(value = "/add/{user_id}", produces = "application/json", method = RequestMethod.POST) public ResponseEntity<Data> addData(@RequestParam("note") String body, @RequestParam("location") String location, @RequestParam(value = "file", required = false) List<MultipartFile> file, @PathVariable String user_id){ if (file != null) { doSomething(file); } doRegularStuff(body, location, user_id); return new ResponseEntity(HttpStatus.OK); } As can be seen, I have the required = false option for my List of multipart files. However, when I attempt to curl the endpoint without any files and while stating that my content type is Content-Type: application/json, I get the error that my request isn't a multipart request.
Fine. So I change to Content-Type: multipart/form-data and without any files, I get the request was rejected because no multipart boundary was found (obviously, since I don't have a file).
This leads me to wonder how I can have a optional multipart parameter in my Spring endpoints? I would like to avoid having to add additional parameters to my request, such as "File Attached: True/False" as that can become cumbersome and unnecessary when the server can just check for existence.
Thanks!

