@@ -255,8 +255,32 @@ def _get_body(self, app: EventHandlerInstance) -> dict[str, Any]:
255
255
256
256
content_type = app .current_event .headers .get ("content-type" , "" ).strip ()
257
257
258
- # Handle JSON content (default)
259
- if not content_type or content_type .startswith ("application/json" ):
258
+ # If no content-type is provided, try to infer from route parameters
259
+ if not content_type :
260
+ route = app .context .get ("_route" )
261
+ if route and route .dependant .body_params :
262
+ # Check if any body params are File or Form types
263
+ from aws_lambda_powertools .event_handler .openapi .params import File , Form
264
+
265
+ has_file_params = any (
266
+ isinstance (getattr (param .field_info , "__class__" , None ), type )
267
+ and issubclass (param .field_info .__class__ , (File , Form ))
268
+ for param in route .dependant .body_params
269
+ if hasattr (param , "field_info" )
270
+ )
271
+
272
+ if has_file_params :
273
+ # Default to multipart for File/Form parameters
274
+ content_type = "multipart/form-data"
275
+ else :
276
+ # Default to JSON for other body parameters
277
+ content_type = "application/json"
278
+ else :
279
+ # Default to JSON when no body params
280
+ content_type = "application/json"
281
+
282
+ # Handle JSON content
283
+ if content_type .startswith ("application/json" ):
260
284
try :
261
285
return app .current_event .json_body
262
286
except json .JSONDecodeError as e :
@@ -301,7 +325,7 @@ def _parse_form_data(self, app: EventHandlerInstance) -> dict[str, Any]:
301
325
parsed = parse_qs (body , keep_blank_values = True )
302
326
303
327
# Convert list values to single values where appropriate
304
- result = {}
328
+ result : dict [ str , Any ] = {}
305
329
for key , values in parsed .items ():
306
330
if len (values ) == 1 :
307
331
result [key ] = values [0 ]
0 commit comments