hapic icon indicating copy to clipboard operation
hapic copied to clipboard

Pyramid non-ascii formdata file upload doesn't work as expected

Open inkhey opened this issue 5 years ago • 0 comments

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

inkhey avatar Nov 07 '19 10:11 inkhey