77from typing import Any , List , Optional
88
99import orjson
10+ from gunicorn .http .body import Body
1011from starlette .datastructures import FormData
1112from fastapi import APIRouter , File , Request , UploadFile
1213from 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