Skip to content

Commit 082c8d0

Browse files
committed
Merge pull request #2227 from mjul/master
Added example of how to send multiple files in one request.
2 parents 9b41308 + 0924069 commit 082c8d0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

AUTHORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,4 @@ Patches and Suggestions
154154
- Константин Подшумок (`@podshumok <https://github.com/podshumok>`_)
155155
- Ben Bass (`@codedstructure <https://github.com/codedstructure>`_)
156156
- Jonathan Wong <[email protected]> (`@ContinuousFunction <https://github.com/ContinuousFunction>`_)
157+
- Martin Jul (`@mjul <https://github.com/mjul>`_)

docs/user/advanced.rst

+24
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@ a length) for your body::
267267
requests.post('http://some.url/chunked', data=gen())
268268

269269

270+
271+
POST Multiple Multipart-Encoded Files
272+
-------------------------------------
273+
274+
You can send multiple files in one request. For example, suppose you want to
275+
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.text
286+
{
287+
...
288+
'files': {'images': 'data:image/png;base64,iVBORw ....'}
289+
'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a',
290+
...
291+
}
292+
293+
270294
Event Hooks
271295
-----------
272296

docs/user/quickstart.rst

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ support this, but there is a separate package which does -
270270
``requests-toolbelt``. You should read `the toolbelt's documentation
271271
<https://toolbelt.rtfd.org>`_ for more details about how to use it.
272272

273+
For sending multiple files in one request refer to the :ref:`advanced <advanced>`
274+
section.
275+
273276

274277
Response Status Codes
275278
---------------------

0 commit comments

Comments
 (0)