hapic
hapic copied to clipboard
Pyramid non-ascii formdata file upload doesn't work as expected
When using pyramid backend and formdata file upload, we may have trouble with utf8 or other non-ascii encoded filename, in api depending on the client implementation of file upload
This is because we need to get a cgi.fieldstorage object. As explain in this issue: https://stackoverflow.com/questions/42213318/cgi-fieldstorage-with-multipart-form-data-tries-to-decode-binary-file-as-utf-8-i in case there is no "filename" field decoding of file is not processed as expected and will not be correctly handled as a files by pyramid.
This trouble happened because in case a file is utf8 encoded, RFC6266 say we should use filename*
instead of filename
in content-disposition of form when encoding is not utf8. requests
python library and httpie
command line do only set filename*
in the utf8 filename case, but not filename
.
There is an issue in cgi lib here about handling properly filename*
in cgi.FieldStorage file:
https://bugs.python.org/issue23434
and a PR proposal here:
https://github.com/python/cpython/pull/6027