> I set an attribute encoding to self.fp because, for each part
> of a multipart/form-data, a new instance of FieldStorage is created,
> and this instance needs to know how to decode bytes.
Set fp.encoding may raise an error (eg. for a read-only object, or an object implemented in C). You should add a new argument to the constructor.
> Maybe I'm missing something here, but sys.stdin is always
> a TextIOWrapper instance, even if set to binary mode
I mean: you should pass sys.stdin.buffer instead of sys.stdin.