From 074d4c8d63837e561aa0f5bbda921a595e9160b8 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Feb 2026 16:12:52 +0900 Subject: [PATCH] =?UTF-8?q?api=EC=84=9C=EB=B2=84=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/site/ocr/prd/WebClientConfig.java | 5 +++ .../ocr/prd/contorllers/ImgController.java | 40 ++++++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/prd/src/main/java/site/ocr/prd/WebClientConfig.java b/prd/src/main/java/site/ocr/prd/WebClientConfig.java index 0e1063d..488511a 100644 --- a/prd/src/main/java/site/ocr/prd/WebClientConfig.java +++ b/prd/src/main/java/site/ocr/prd/WebClientConfig.java @@ -2,6 +2,7 @@ package site.ocr.prd; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; @Configuration @@ -13,4 +14,8 @@ public class WebClientConfig { .build(); } + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } } \ No newline at end of file diff --git a/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java b/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java index be82047..03b12ab 100644 --- a/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java +++ b/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java @@ -1,20 +1,50 @@ package site.ocr.prd.contorllers; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; @RestController public class ImgController { + + private final RestTemplate restTemplate; + + @Autowired + public ImgController(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } @PostMapping("img/get-img") - public void postGetImg(@RequestPart("image") MultipartFile image) { - image.getResource(); + public ResponseEntity postGetImg(@RequestPart("image") MultipartFile image) { System.out.println("image :: " + image.getResource().getFilename()); + + //헤더 설정(이미지) + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + //바디에 이미지 파일 추가 + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("image", image.getResource()); + + //요청 엔티티 생성 + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + + //요청 전송 + ResponseEntity response = + restTemplate.postForEntity("http://localhost:9002/ocr", + requestEntity, String.class); + + return ResponseEntity.ok(response.getBody()); } }