Skip to content
Myr

Merge pull request #2227 from mjul/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Added example of how to send multiple files in one request.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 9b41308, 0924069 · Browse files · 3 files+28 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−0 removed

  • other:+28 added−0 removed

3 files+28 added−0 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+3 added
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.275276277Response Status Codes278---------------------279280We can check the response status code::
168 unmodified lines
modified:AUTHORS.rst+1 added
152 unmodified lines
153- Erik Wickstrom <erik@erikwickstrom.com> (`@erikwickstrom <https://github.com/erikwickstrom>`_)154- Константин Подшумок (`@podshumok <https://github.com/podshumok>`_)155- Ben Bass (`@codedstructure <https://github.com/codedstructure>`_)156- Jonathan Wong <evolutionace@gmail.com> (`@ContinuousFunction <https://github.com/ContinuousFunction>`_)157- Martin Jul (`@mjul <https://github.com/mjul>`_)