11from starlette .datastructures import Headers
2- from pydantic import BaseModel , Field , field_validator , ByteSize , ConfigDict , AliasChoices
2+ from pydantic import BaseModel , Field , StrictStr , field_validator , ByteSize , ConfigDict , AliasChoices
33from typing import Optional , Self , Annotated
44
55
66class FileMetadata (BaseModel ):
7- name : str = Field (description = "File name" , min_length = 1 , max_length = 255 )
7+ name : StrictStr = Field (description = "File name" , min_length = 1 , max_length = 255 )
88 size : ByteSize = Field (description = "Size in bytes" , gt = 0 )
9- type : str = Field (description = "MIME type" , default = 'application/octet-stream' )
9+ type : StrictStr = Field (description = "MIME type" , default = 'application/octet-stream' )
1010
1111 model_config = ConfigDict (title = "File transfer metadata" , alias_generator = lambda s : f'file_{ s } ' , populate_by_name = True , validate_by_name = True )
1212
@@ -29,7 +29,7 @@ def get_from_http_headers(cls, headers: Headers, filename: str) -> Self:
2929 return cls (
3030 name = filename ,
3131 size = headers .get ('content-length' , '0' ),
32- type = headers .get ('content-type' , '' )
32+ type = headers .get ('content-type' , '' ) # Must be a string
3333 )
3434
3535 @classmethod
0 commit comments