Skip to content

Commit e99f51a

Browse files
committed
Fixed issues with json processing /process.
1 parent 268700c commit e99f51a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ocr_service/api/api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, List, Optional
88

99
import orjson
10+
from gunicorn.http.body import Body
1011
from starlette.datastructures import FormData
1112
from fastapi import APIRouter, File, Request, UploadFile
1213
from fastapi.responses import ORJSONResponse, Response
@@ -55,7 +56,12 @@ def process(request: Request, file: Optional[UploadFile] = File(default=None)) -
5556
else:
5657
file_name = uuid.uuid4().hex
5758
log.info(f"Processing binary as data-binary, generated file name: {file_name}")
58-
raw_body = request._body
59+
60+
environ: dict = request.scope.get("wsgi_environ", {})
61+
input_stream: Body = environ.get("wsgi.input", {})
62+
63+
content_length = int(environ.get("CONTENT_LENGTH", 0))
64+
raw_body = input_stream.read(content_length) if content_length > 0 else b""
5965

6066
try:
6167
record = orjson.loads(raw_body)
@@ -68,7 +74,7 @@ def process(request: Request, file: Optional[UploadFile] = File(default=None)) -
6874
if stream not in [None, "", {}]:
6975
stream = base64.b64decode(stream)
7076
except Exception:
71-
log.warning("Binary_data field could not be base64 decoded")
77+
log.warning("Binary_data xf could not be base64 decoded")
7278
stream = record.get("binary_data", {})
7379

7480
footer = record.get("footer", {})

0 commit comments

Comments
 (0)