I have a problem to send requestBody and multipartFile in Controller of Spring Boot from Postman.
I get this issue shown below as an image
Here is the method of controller shown below
@PostMapping(produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> createQrCode(@RequestBody CreateQrRequest request, @RequestPart MultipartFile imageFile) throws IOException {
}
Here is CreateQrRequest shown below
@Data
@Builder
public class CreateQrRequest {
@NotBlank
private String text;
@NotBlank
private String size;
@NotBlank
private String color;
@NotBlank
private String backgroundColor;
}
Here is the error message when I tried to define the parameters like
public ResponseEntity<byte[]> createQrCode(@RequestPart CreateQrRequest request,
@RequestPart MultipartFile imageFile) throws IOException {
Error Message
{
"type": "about:blank",
"title": "Unsupported Media Type",
"status": 415,
"detail": "Content-Type 'application/octet-stream' is not supported.",
"instance": "/api/v1/qr-generator"
}
How can I fix it?
You can change the controller like below -
@PostMapping(produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> createQrCode(@RequestPart String text, @RequestPart String size, @RequestPart String color, @RequestPart String backgroundColor, @RequestPart MultipartFile imageFile) throws IOException {
}
Just writing the request's attributes separately.