diff --git a/AUTHORS.rst b/AUTHORS.rst index 1ab53ef83a..1e084d8f6b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -154,3 +154,4 @@ Patches and Suggestions - Константин Подшумок (`@podshumok `_) - Ben Bass (`@codedstructure `_) - Jonathan Wong (`@ContinuousFunction `_) +- Martin Jul (`@mjul `_) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index d285c18108..b5758369d2 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -267,6 +267,30 @@ a length) for your body:: requests.post('http://some.url/chunked', data=gen()) + +POST Multiple Multipart-Encoded Files +------------------------------------- + +You can send multiple files in one request. For example, suppose you want to +upload image files to an HTML form with a multiple file field 'images': + + + +To do that, just set files to a list of tuples of (form_field_name, file_info): + + >>> url = 'http://httpbin.org/post' + >>> multiple_files = [('images', ('foo.png', open('foo.png', 'rb'), 'image/png')), + ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))] + >>> r = requests.post(url, files=multiple_files) + >>> r.text + { + ... + 'files': {'images': 'data:image/png;base64,iVBORw ....'} + 'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a', + ... + } + + Event Hooks ----------- diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 1a4b271459..9d4e690436 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -270,6 +270,9 @@ support this, but there is a separate package which does - ``requests-toolbelt``. You should read `the toolbelt's documentation `_ for more details about how to use it. +For sending multiple files in one request refer to the :ref:`advanced ` +section. + Response Status Codes ---------------------