@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<String> postGetImg(@RequestPart("image") MultipartFile image) {
|
||||
System.out.println("image :: " + image.getResource().getFilename());
|
||||
|
||||
//헤더 설정(이미지)
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
//바디에 이미지 파일 추가
|
||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||
body.add("image", image.getResource());
|
||||
|
||||
//요청 엔티티 생성
|
||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||
|
||||
//요청 전송
|
||||
ResponseEntity<String> response =
|
||||
restTemplate.postForEntity("http://localhost:9002/ocr",
|
||||
requestEntity, String.class);
|
||||
|
||||
return ResponseEntity.ok(response.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user