ocrService.ts 661 B

123456789101112131415161718192021222324
  1. import { apiClient } from './apiClient';
  2. /**
  3. * OCR サービス - 画像テキスト認識関連の処理を担当
  4. */
  5. export const ocrService = {
  6. // 画像内のテキストを認識
  7. async recognizeText(authToken: string, image: Blob): Promise<string> {
  8. const formData = new FormData();
  9. formData.append('image', image);
  10. const response = await apiClient.request('/ocr/recognize', {
  11. method: 'POST',
  12. body: formData,
  13. });
  14. if (!response.ok) {
  15. throw new Error('Failed to recognize text');
  16. }
  17. const data = await response.json();
  18. return data.text;
  19. }
  20. };