Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4012 Updated the docs to reflect need of decoding filename #5831

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES/5831.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
In the current version, the filenames are encoded before sending the files to the server when using FormData() object.
This problem has already been posted in #4012.
Its fix has been discussed in #4031 will be added in aiohttp v3.8.
Updated the docs to help users know the problem and its fix for now.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Tolga Tezel
Tomasz Trebski
Toshiaki Tanaka
Trinh Hoang Nhu
Tushar Singh
Vadim Suharnikov
Vaibhav Sagar
Vamsi Krishna Avula
Expand Down
20 changes: 20 additions & 0 deletions docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ You can set the ``filename`` and ``content_type`` explicitly::

await session.post(url, data=data)

If you are sending files using ``FormData`` payload, it will automatically encode the filenames into `urlencoding` format.
for example, file_name and encoded_file_name will look this ::

file_name = "form file.txt"
encoded_file_name = "form%20file.txt"

This could lead to unexpected behavior on the server side while handling filenames. To decode the encoded_file_name, we can use python's ``urllib`` module.
following snippet shows how we can use the ``urllib`` to decode the filename::

import urllib.parse
encoded_file_name = "form%20file.txt"
decoded_file_name = urllib.parse.unquote(encoded_file_name)
print(decoded_file_name)

Prints::

"form file.txt"

In upcoming ``aiohttp v3.8``, filenames will not be encoded before sending it to the server and need of decoding will not neccessary.

If you pass a file object as data parameter, aiohttp will stream it to
the server automatically. Check :class:`~aiohttp.StreamReader`
for supported format information.
Expand Down