From c2ed5b7b72743b049be677f8bbbf0a686e7b7e2e Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Thu, 24 Jun 2021 14:02:07 +0530 Subject: [PATCH 1/3] Updated the docs to reflect need of decoding filename issue #4012 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. --- docs/client_quickstart.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst index 7f7d44caad0..2c67b6fc85b 100644 --- a/docs/client_quickstart.rst +++ b/docs/client_quickstart.rst @@ -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. From 579410c84d2eb48e243bce8dfdf664237fe89dcc Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Thu, 24 Jun 2021 14:59:02 +0530 Subject: [PATCH 2/3] Create 5831.doc --- CHANGES/5831.doc | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGES/5831.doc diff --git a/CHANGES/5831.doc b/CHANGES/5831.doc new file mode 100644 index 00000000000..761a51780b8 --- /dev/null +++ b/CHANGES/5831.doc @@ -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. From 5e68db47ea3168a44c77a1a351a52557cee6892a Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Thu, 24 Jun 2021 15:01:01 +0530 Subject: [PATCH 3/3] Update CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index f9544ce9b08..c331d04eb61 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -285,6 +285,7 @@ Tolga Tezel Tomasz Trebski Toshiaki Tanaka Trinh Hoang Nhu +Tushar Singh Vadim Suharnikov Vaibhav Sagar Vamsi Krishna Avula