File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -778,17 +778,25 @@ async def post(self) -> "MultiDictProxy[str | bytes | FileField]":
778778 out .add (field .name , ff )
779779 else :
780780 # deal with ordinary data
781- value = await field .read (decode = True )
781+ raw_data = bytearray ()
782+ while chunk := await field .read_chunk ():
783+ size += len (chunk )
784+ if 0 < max_size < size :
785+ raise HTTPRequestEntityTooLarge (
786+ max_size = max_size , actual_size = size
787+ )
788+ raw_data .extend (chunk )
789+
790+ value = bytearray ()
791+ # form-data doesn't support compression, so don't need to check size again.
792+ async for d in field .decode_iter (raw_data ):
793+ value .extend (d )
794+
782795 if field_ct is None or field_ct .startswith ("text/" ):
783796 charset = field .get_charset (default = "utf-8" )
784797 out .add (field .name , value .decode (charset ))
785798 else :
786799 out .add (field .name , value )
787- size += len (value )
788- if 0 < max_size < size :
789- raise HTTPRequestEntityTooLarge (
790- max_size = max_size , actual_size = size
791- )
792800 else :
793801 raise ValueError (
794802 "To decode nested multipart you need to use custom reader" ,
You can’t perform that action at this time.
0 commit comments