OcrController.java
1.16 KB
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
32
33
34
35
36
37
package com.xly.ocr.web;
import com.xly.ocr.service.OcrService;
import com.xly.tts.bean.TTSResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@RestController
@RequestMapping("/api/ocr")
public class OcrController {
@Autowired
private OcrService ocrService;
@PostMapping("/extract")
public ResponseEntity<TTSResponseDTO> extractText(
@RequestParam("file") MultipartFile file) {
String result = ocrService.extractTextFromMultipartFile(file);
TTSResponseDTO dto= TTSResponseDTO.builder()
.code(200)
.message("操作成功")
.processedText(result)
.build();
return ResponseEntity.ok(dto);
}
// @PostMapping("/batch")
// public ResponseEntity<List<String>> batchExtract(
// @RequestParam("files") List<MultipartFile> files) {
// List<String> results = ocrService.batchExtractText(files);
// return ResponseEntity.ok(results);
// }
}