1

I am writing a backend api which consumes a json request with multipart image files. I am unable to figure out a way to do so. Anyone, faced and found a solution to a problem similar to mine...???

1 Answers1

0

You can define a Spring Controller endpoint accepting a DTO and a MultipartFile parameter

@RestController
@RequestMapping("/svc")
public class MyController {

  @PostMapping
  public String create(
    @RequestPart(name = "dto") Dto dto, // my Java DTO
    @RequestPart(value = "file") MultipartFile file) throws Exception {
  
}

You should be able to use MultipartFile[] files if you need to consume multiple files.

Beppe C
  • 11,256
  • 2
  • 19
  • 41