Moved multiple files upload example to advanced section.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Martin Jul · committed by Martin Jul · parent 4707d11 · Browse files · 2 files·+26 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+26 added−23 removed
- other:+26 added−23 removed
Provenance
- Commit
0924069- Tree
3c406d9- Author
Martin Jul <martin@mjul.com>- Committer
Martin Jul <martin@mjul.com>- Parent
4707d11
2 files changed+26 added−23 removed
modified:docs/user/advanced.rst+24 added
265 unmodified lines266 267 requests.post('http://some.url/chunked', data=gen())268 269 270+271+POST Multiple Multipart-Encoded Files272+-------------------------------------273+274+You can send multiple files in one request. For example, suppose you want to275+upload image files to an HTML form with a multiple file field 'images':276+277+ <input type="file" name="images" multiple="true" required="true"/>278+279+To do that, just set files to a list of tuples of (form_field_name, file_info):280+281+ >>> url = 'http://httpbin.org/post'282+ >>> multiple_files = [('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),283+ ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]284+ >>> r = requests.post(url, files=multiple_files)285+ >>> r.text286+ {287+ ...288+ 'files': {'images': 'data:image/png;base64,iVBORw ....'}289+ 'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a',290+ ...291+ }292+293+294 Event Hooks295 -----------296 297 Requests has a hook system that you can use to manipulate portions of488 unmodified linesmodified:docs/user/quickstart.rst+2 added-23 removed
268 unmodified lines269 support this, but there is a separate package which does -270 ``requests-toolbelt``. You should read `the toolbelt's documentation271 <https://toolbelt.rtfd.org>`_ for more details about how to use it.272 273+For sending multiple files in one request refer to the :ref:`advanced <advanced>`274+section.275 274-POST Multiple Multipart-Encoded Files275--------------------------------------276 277-You can send multiple files in one request. For example, suppose you want to278-upload image files to an HTML form with a multiple file field 'images':279-280- <input type="file" name="images" multiple="true" required="true"/>281-282-To do that, just set files to a list of tuples of (form_field_name, file_info):283-284- >>> url = 'http://httpbin.org/post'285- >>> multiple_files = [('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),286- ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]287- >>> r = requests.post(url, files=multiple_files)288- >>> r.text289- {290- ...291- 'files': {'images': 'data:image/png;base64,iVBORw ....'}292- 'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a',293- ...294- }295-296-297-277 Response Status Codes278 ---------------------279 280 We can check the response status code::168 unmodified lines