Skip to content
Myr

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

2 files+26 added−23 removed

modified:docs/user/advanced.rst+24 added
265 unmodified lines
266267 requests.post('http://some.url/chunked', data=gen())268269270271POST Multiple Multipart-Encoded Files272-------------------------------------273274You can send multiple files in one request. For example, suppose you want to275upload image files to an HTML form with a multiple file field 'images':276277 <input type="file" name="images" multiple="true" required="true"/>278279To do that, just set files to a list of tuples of (form_field_name, file_info):280281 >>> 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 }292293294Event Hooks295-----------296297Requests has a hook system that you can use to manipulate portions of
488 unmodified lines
modified:docs/user/quickstart.rst+2 added-23 removed
268 unmodified lines
269support 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.272273For sending multiple files in one request refer to the :ref:`advanced <advanced>`274section.275274POST Multiple Multipart-Encoded Files275-------------------------------------276277You can send multiple files in one request. For example, suppose you want to278upload image files to an HTML form with a multiple file field 'images':279280 <input type="file" name="images" multiple="true" required="true"/>281282To do that, just set files to a list of tuples of (form_field_name, file_info):283284 >>> 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 }295296297277Response Status Codes278---------------------279280We can check the response status code::
168 unmodified lines