Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3619

How to consume Request Body (JSON) along with multiple files (multipart/form-data) via REST API in Spring Boot?

$
0
0

I want to consume both JSON & files in an API for my spring boot application (using Spring WebFlux). I tried multiple ways as was recommended over the internet (Article1, Article2, Article3), but it's not working for me. The API is not being hit and getting status 415 (Unsupported Media Type) from Postman.

Spring-Boot version : 2.5.3

Spring-Web/Webflux version : 5.3.9

Employee :

@Data@NoArgsConstructor@AllArgsConstructorpublic class Employee {    private String name;    private int age;    private int mobileNo;    private List<MultipartFile> files;}

Controller :

@PostMapping(path = "employee", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})public Mono<Response> processEmployeeDocs(@RequestPart Employee request, @RequestPart List<MultipartFile> files) {    Employee employee = new Employee(request.getName(), request.getAge(), request.getMobileNo(), files);    return employeeService.processDocs(employee);}

Viewing all articles
Browse latest Browse all 3619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>