-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcrController.java
More file actions
31 lines (25 loc) · 976 Bytes
/
OcrController.java
File metadata and controls
31 lines (25 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.ocr.controller;
import com.example.ocr.service.OcrService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Map;
@RestController
@RequestMapping("/upload")
@CrossOrigin(origins = "*") // CORS 허용
public class OcrController {
private final OcrService ocrService;
public OcrController(OcrService ocrService) {
this.ocrService = ocrService;
}
@PostMapping
public ResponseEntity<Map<String, String>> uploadFile(@RequestParam("file") MultipartFile file) {
try {
String text = ocrService.extractText(file);
return ResponseEntity.ok(Map.of("text", text));
} catch (IOException e) {
return ResponseEntity.badRequest().body(Map.of("error", "파일 처리 중 오류 발생"));
}
}
}