Skip to content

Commit

Permalink
Moved multiple files upload example to advanced section.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjul committed Sep 16, 2014
1 parent 4707d11 commit 0924069
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
24 changes: 24 additions & 0 deletions docs/user/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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':

<input type="file" name="images" multiple="true" required="true"/>

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
-----------

Expand Down
25 changes: 2 additions & 23 deletions docs/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,8 @@ support this, but there is a separate package which does -
``requests-toolbelt``. You should read `the toolbelt's documentation
<https://toolbelt.rtfd.org>`_ for more details about how to use it.


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':

<input type="file" name="images" multiple="true" required="true"/>

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',
...
}

For sending multiple files in one request refer to the :ref:`advanced <advanced>`
section.


Response Status Codes
Expand Down

0 comments on commit 0924069

Please sign in to comment.