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...???
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.